-1

I am looking for a way to run a script (python, js, node.js, or any other suggestion) that will take a screenshot of a defined area of a pdf. The ideal functionality is being able to run a shell script that allows me to select a pdf file that I have downloaded, define the coordinate area of the pdf that I would like to capture in the screenshot, and then save that screenshot to the same directory as the original file.

Does anyone have any idea how/if this can be done, and in what language it would work best in?

Roger99
  • 981
  • 2
  • 11
  • 42
  • https://stackoverflow.com/questions/51872656/how-to-take-a-screenshot-in-pdf-using-javascript – Zach M. Nov 26 '18 at 19:44
  • You need a PDF rendering library to make a raster image from the PDF, then you need an image library to handle grabbing a rect from the image. You may be able to go straight to SVG in html canvas and grab a image direct from that. – Vanquished Wombat Nov 26 '18 at 22:50

1 Answers1

1

I accomplished the above task by using 2 tools, pdftk and Imagemagick.

I went through my pdfs, cut the pdfs into individual pages, turned them into pngs, and then cropped those pngs. My code is as follows:

pdftk "Pies for Daily.pdf" cat 1 output pdfs/percent_burned_pie.pdf

magick -density 600 pdfs/percent_burned_pie.pdf -quality 100 -crop 2300x2350+450+450 images/percent_burned_pie.png
Roger99
  • 981
  • 2
  • 11
  • 42