r - Selecting pdf pages for multiple PDFs saved in a list - Stack Overflow

I am using the pdftools package to read in a pdf file in R.I've used the following code which wor

I am using the pdftools package to read in a pdf file in R.

I've used the following code which works for the 1 pdf file I have (although it is designed to read in multiple files from my wd if needed):

    files <- list.files(pattern = "pdf$")
    mypdf <- lapply(files, pdf_text)
    corp <- Corpus(URISource(files),
               readerControl = list(reader = readPDF))

How can I select specific pages from my 1 pdf (or a specific pdf) within my files/wd? e.g. I only want to read in pages 10:16

I tried applying brackets [10:16] after pdf_text(), but this didn't work

I am using the pdftools package to read in a pdf file in R.

I've used the following code which works for the 1 pdf file I have (although it is designed to read in multiple files from my wd if needed):

    files <- list.files(pattern = "pdf$")
    mypdf <- lapply(files, pdf_text)
    corp <- Corpus(URISource(files),
               readerControl = list(reader = readPDF))

How can I select specific pages from my 1 pdf (or a specific pdf) within my files/wd? e.g. I only want to read in pages 10:16

I tried applying brackets [10:16] after pdf_text(), but this didn't work

Share Improve this question edited Mar 3 at 14:47 jpsmith 18k6 gold badges23 silver badges45 bronze badges asked Mar 3 at 13:51 user29870836user29870836 211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You are saving your PDFs to a list, so that's why the brackets aren't working as expected. mypdf[10:16] would work if your object was a single PDF, but since you have multiple PDFs in a list, you need to use lapply:

lapply(mypdf, \(x) x[10:16])

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745091831a4610737.html

相关推荐

  • r - Selecting pdf pages for multiple PDFs saved in a list - Stack Overflow

    I am using the pdftools package to read in a pdf file in R.I've used the following code which wor

    18小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信