Using R, how can I count the number of pages in a PDF file?

I have about a hundred long PDF files in a directory and would like to know if R can count how many pages in each file. My operating system is Windows 8.

Here is a link to a 10-page PDF file if this helps you test your solution. PDF file MWE

It looks like you can calculate PDF pages using python, but I don't know what is the python language solution . Other solutions were discussed on SO using, for example, Imagemagick. and C ##.

+4
source share
2 answers

In version R 3.3.2, it pdftoolsworks:

library(pdftools)
pdfInfo <- pdf_info(<path to PDF file>)
pdfInfo$pages
0
source

Windows 7, Windows 8 , .

Rpoppler, , hrbrmstr, , , . 7-Zip, poppler Windows. C:\poppler.

file_name <- "C:/[file_path]/whitepaper-pdfprimer.pdf"

pdf_pages <- function(file_name){
  require(magrittr)
  pages <- system2("C:/poppler/bin/pdfinfo.exe",
                   args = file_name,
                   stdout = TRUE)
  pages[grepl("Pages:", pages)] %>%
    gsub("Pages:", "", .) %>%
    as.numeric()
}

pdf_pages(file_name)

,

vapply(file_names, pdf_pages, numeric(1))

@hrbrmstr poppler ( ).

0

Source: https://habr.com/ru/post/1612410/


All Articles