stats_noob
stats_noob

Reputation: 5907

How to split pdf document into multiple pages?

I have a big pdf document (100 pages) on my computer, I am trying to save each page individually as a pdf (e.g. page_1.pdf, page_2.pdf, etc.).

I figure out how to import the big pdf:

library(pdftools)

#https://alexluscombe.ca/blog/getting-your-.pdfs-into-r/
#read in pdf document using pdf_text() function

pdf_report <- pdf_text("~/Desktop/personal-website/Blog_Files/big_pdf.pdf")`

But I am unsure how to save each page in this pdf document as individual pdfs. I know this can be done manually in ADOBE VIEWER, but this will take took long.

I try this code:

library(pdftools)
pdf_report <- pdf_text("pdf_report.pdf")
a = pdf_subset(pdf_report,
               pages = 1, output = "subset_a.pdf")

But I get error: Error in get_input(input) : input should contain exactly one file

How I can please fix this?

Upvotes: 1

Views: 653

Answers (1)

jay.sf
jay.sf

Reputation: 72893

You may use qpdf::pdf_split which is imported by pdftools.

qpdf::pdf_split('pdf_report.pdf')
# [1] "/home/jay/pdf_report_000000000000000000000001.pdf" "/home/jay/pdf_report_000000000000000000000002.pdf"
# [3] "/home/jay/pdf_report_000000000000000000000003.pdf" "/home/jay/pdf_report_000000000000000000000004.pdf"
# [5] ...

Upvotes: 1

Related Questions