Linked Questions

Popular Questions

How to count the number of pages in a PDF from R?

Asked by At

Is there a way to count the number of pages in a PDF file from R? If not, is there another OS-independent way to do this? So far, the only answer I have found is this, and it is specific to Windows 7.

I am trying to compile some reports in R and knitr, aggregating the PDF plot output from a previous script, which automatically processes hundreds of data sets. Some of the datasets are bad, and end up breaking the plot function. Since the plot function is wrapped in the pdf function, an empty PDF file gets produced, is found by the report, and breaks pdflatex. Trying to modify the analysis script to avoid producing these PDF's in the first place has proven to be difficult, and is very case-specific. I would really like to have some function which I can embed in the report that will check the PDF for >=1 page(s) before including it. I would prefer an R based solution, though a bash, LaTeX, knitr, or pdflatex solution might also suffice.

EDIT: Also, as is mentioned in the previous answer I linked to, I tried to use Rpoppler (here) but cannot get it to compile. I am using R version 3.3.0 in a CentOS 6 environment without admin access.

Related Questions