Turn PDFs containing "flash cards" into individual 4x6 JPGs

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
movingclouds

Turn PDFs containing "flash cards" into individual 4x6 JPGs

Post by movingclouds »

What is the quickest way to turn the PDFs with printable flash cards (that need post-printing cutting) into 4x6 JPEGs, where each 4x6 JPEG has 2 flash cards side-to-side?

PDFs are here:
http://sn.im/revisedgrammarcards
and
http://sn.im/words1-50


The revisedgrammarcards PDF has 11 pages with a total of 62 "flash card" boxes/rectangles. 2 flahscard boxes should be one 4x6 JPG, for a total of 31 JPGs.

The words1-50 PDF has 9 pages with a total of 50 boxes. So there should be a total of 25 JPGs.

By the way, the boxes have a black rectangle outline around each one. When I convert them to JPG, I don't need the black outline, but I do need everything inside them.

Thank you.

P.S. If there is a tool better than ImageMagick in doing this efficiently, please let me know. I post here on the suggestion of a user at the Gimp Chatroom.
Last edited by movingclouds on 2009-11-11T18:12:29-07:00, edited 1 time in total.
movingclouds

Some samples

Post by movingclouds »

Here is how I wish the final product to look like. I used Gimp to produce this. I did so one-by-one.


Image


----

Image

--------------

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Turn PDFs containing "flash cards" into individual 4x6 JPGs

Post by fmw42 »

This should work with your pdfs, but I get an error when trying to read the pdf due to illegal/unknown fonts, presumably your Hebrew font. So I used another tool to export one page of your word1-50 file to a png and then processed it as follows.

First line: chop off the bottom 150 rows to get rid of the page number in the lower right corner
Second line: add 150 rows of white back to keep the image size the same
Third line: crop the image into 6 equal size pieces (50% width and 33% height) and then trim all the white until it gets to the black border of each and store as test-0.jpg, test-1.jpg ... etc. (The black border is important for the trim to know where to stop)

convert test.png -gravity south -chop 0x150 \
-background white -splice 0x150 \
+gravity -crop 50x33.333% -trim test_%d.jpg
movingclouds

Re: Turn PDFs containing "flash cards" into individual 4x6 JPGs

Post by movingclouds »

fmw42,
thanks for your reply. since I can read hebrew on my comp, I perhaps wouldn't get an error. I'd like to try chopping the file from the original PDF format. I tried

Code: Select all

convert 1-50.pdf to 1.png 
but the resolution has shrank!

Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Turn PDFs containing "flash cards" into individual 4x6 JPGs

Post by fmw42 »

there is no command "to"

you also generally need to tell the PDF what resolution you want when you read it in, but I am not sure what exact value to tell you, so you may have to play with the density value (72, 150, 300) are typical. But you can adjust for the size you want or use -resize to tell it the number of pixels you want in width and height.

convert -density 300 image.pdf image_%d.png

the _%d will assign a number, in this case, _0, _1, _2 ... for each page of the pdf.
Post Reply