Hello all,
I have a pdf that has many cards layed out touching each other.
I’d like to import these into a module I have.
I’ve looked all over youtube and haven’t found a solution to this yet, does anyone know what to do?
Thanks!!!
Hello all,
I have a pdf that has many cards layed out touching each other.
I’d like to import these into a module I have.
I’ve looked all over youtube and haven’t found a solution to this yet, does anyone know what to do?
Thanks!!!
Hi,
If the cards in the PDF are really independent images, then you may have some luck with pdfimages
from poppler (see [here](https://github.com/oschwartz10612/poppler-windows_ for Windows) or XPdfReader. Running that on your PDF - say cards.pdf
like
pdfimages cards.pdf
could produce a number of images with the cards in them.
Some PDF viewers - for example Evince - allows you to select and image and save it to disk.
Another option is to use something like pdftocairo
- part of poppler - to convert all the pages into PNG, SVG, JPG, TIF. You can then use your favorite image manipulation program (e.g. Gimp) to crop out the individual cards. Of course, if the cards are layed out nicely and consistenly on the pages, then you can probably write a small Python script using Pillow to crop the cards out.
Hope that helps.
Yours,
Christian
For a multi-page PDF with an 8x3 table of cards on each page, most installations of Linux include the necessary command-line utilities to do this: poppler-utils
and imagemagick
.
(If you are not on Linux or don’t have access to it, perhaps you can apply these steps to your own OS using analogous principles.)
Place your multi-page PDF file into its own folder, for example: cardworks
In the Linux terminal, navigate to the cardworks folder using the cd command. For example, if cardworks is in your home folder:
cd cardworks
ls -l
pdftoppm input.pdf outputname -png
Instead of input.pdf, use the filename of your own PDF. This will output each page of the PDF to its own PNG file using the format outputname-xx.png, with xx being the index of the page.
mogrify -trim *.png
trim is sometimes called “auto-crop” because it automatically attempts to remove edges of an image which do not change in color or transparency.
convert outputname*.png -crop 8x3@ mycards_%02d.png
The part of the file name %02d is an auto-increment flag.
Job done.
The -crop command as given will create images that can vary by a pixel in width and height if the cropped image is not evenly divisible by 8 and 3 respectively.
Here are two additional steps to unify the size of the cards and give them a border.
\!
flag:
mogrify -resize 143×248\! mycards*.png
mogrify -bordercolor Black -border 1×1 mycards*.png
This make all cards 145 x 250 pixels.
If you have GIMP installed you might find the linked article useful. GIMP will import pdf files.
I used to have a GIMP plug-in that quickly sliced an image into X times Y pieces. It may still be around if you can find it.
A similar technique will probabably be available in your favourite graphics editor.
Have fun,
Reg