0

I receive a single page A4 PDF file from my shipping courier. It contains a small label on the top left corner, and the rest of the page is blank. As I usually have to print several a day, I end up wasting a lot of paper. I could drop all the PDFs to inkscape (it imports the label as a grouped object) and manually align them to fit an A4 page. But it will become tedious really fast and it would waste time.

Can you point me in the right direction as to what to look for in order to write a python script to do this?

martineau
  • 119,623
  • 25
  • 170
  • 301
J.Nada
  • 1
  • 1
  • For how to process PDFs, there is already a [similar question](https://stackoverflow.com/q/45795089/11384184), one answer being a reference to [a chapter from Automate the Boring Stuff with Python](https://automatetheboringstuff.com/chapter13/) which sounds exactly like what you want to do. – Lenormju Jun 08 '21 at 12:57
  • I'm reading that today, thanks. – J.Nada Jun 09 '21 at 14:27

2 Answers2

1
  • You would need to determine the size of the label in PDF units (1 point = 1/72 inch).

  • Then determine how many labels you can fit onto one page, i.e. how many columns and rows you can have (taking the needed printing margin into account).

  • The script could take the PDF pages as command line arguments, import each page as Form XObject and place the labels into the row/column raster.

gettalong
  • 735
  • 3
  • 10
0

I would do the following:

Once:

  • Create a file with a different linked image for each label that fits on the page (with correct proportions)

For each label file (Inkscape command line):

  • Open with Inkscape
  • Create an object of the size of the label and clip the contents to that object (if necessary, e.g. because there's more in the file than just that single group object)
  • Resize page to contents
  • Save

Then:

  • create a CSV file from your current set of label file names, suitable for https://gitlab.com/Moini/nextgenerator - as many as fit on one page per line
  • use the extension (see documentation)

Note that the extension can also be used from the command line, if needed.

Moini
  • 1,239
  • 9
  • 10