Importing cards to a vassal module

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.)

  1. Place your multi-page PDF file into its own folder, for example: cardworks

  2. In the Linux terminal, navigate to the cardworks folder using the cd command. For example, if cardworks is in your home folder:

cd cardworks

  1. Confirm that you are in the correct folder. This should display only one file in the folder, which is your starting multi-page PDF:

ls -l

  1. Convert a multi-page PDF to a PNG:

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.

  1. Remove the white space around the grouped cards on each PNG file, retaining existing file names:

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.

  1. Slice each outputname-xx.png file into individual card PNG files, specifying the filename format of the output files:

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.

  1. Resize images so they are all the same dimensions; ignoring aspect ratio with the \! flag:

mogrify -resize 143×248\! mycards*.png

  1. Add a 1-pixel black border around each card:

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.

Slicing Images Using GIMP

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

1 Like