4

I have hundreds of PDFs that I want to crop. For each PDF, I have a unique set of coordinates around which to crop. I am trying to use the R's magick package (version ImageMagick 6.9.9.14), but I receive an error when importing a PDF.

This example from the magick documentation throws an error:

 library(magick)
 manual <- image_read('https://cran.r-project.org/web/packages/magick/magick.pdf', density = "72x72")

The error I receive is "Error in magick_image_readpath(path, density, depth, strip) : Magick: PDFDelegateFailed `The system cannot find the file specified. ' @ error/pdf.c/ReadPDFImage/809"

When I check the config settings:

magick_config

I find that ghostscript is true. I am not sure if there are other settings required for reading in a PDF.

Has anyone else encountered a similar problem with magick? I am open to alternative packages with the ability to crop PDFs, if there are any.

Amberopolis
  • 445
  • 1
  • 6
  • 16
  • I had the same problem on Windows. In my case, I sued ImageMagick 64 bit but had GhostScript 32-bit installed. After installing the 64-bit version it worked. – Mark Heckmann Feb 21 '18 at 19:36
  • @MarkHeckmann where were you 6 days ago!?! This fixed my problem completely. If you want to submit it as an answer, I'll accept it. – Amberopolis Feb 22 '18 at 19:24
  • haha, sorry, next time I will try to have the issue earlier ;) PS. I posted it. – Mark Heckmann Feb 22 '18 at 19:33

2 Answers2

3

I had the same problem on Windows. It was no R problem. In my case, I used ImageMagick 64-bit but had GhostScript 32-bit installed. After installing the 64-bit version of GhostScript it worked without any issues.

Mark Heckmann
  • 10,943
  • 4
  • 56
  • 88
  • This helped me, but I also had to install `pdftools` and I had to use `image_read_pdf` instead of `image_read`. – Nova Nov 14 '19 at 16:48
0

You could use tabulizer package.

library(tabulizer)
manual_url <- "https://cran.r-project.org/web/packages/magick/magick.pdf" 
manual <- extract_text(manual_url) 

For installing tabulizer follow exactly these steps.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
  • tabulizer is a great package, but it doesn't really help here, because I am not interested in the text. I am only interesting in trying to crop the images. And loading the file with tabulizer doesn't produce a magick image object that the magick package can crop. – Amberopolis Feb 22 '18 at 19:13