I'm working on a project to automate the creation of shipping labels, (Avery 8127) to be exact. I get a PNG of the USPS/UPS/FedEx shipping label, but the packing slip can vary between a PDF or a screenshot of a webpage.

My initial (quasi successful) solution was to use ImageMagick to manipulate the USPS label, convert the packing slip to a PNG and again, use ImageMagick to append them together to create a single graphics file with both images laid out correctly.

However, this isn't ideal. I'd like the ability to generate a new document (whatever it may be, PDF, PS, image, etc.) where I layout the graphic where it needs to be and insert the text below it. I'd like to have the ability to change the font size or add/remove text as needed.

What tools are available for this type of thing? How can I create and lay out a new document programmatically based on a graphics file and a file containing text?

(Could I do this with a CUPS printer filter?)

I'm currently working on macOS, but I'm looking for something portable so I can easily move it to a FreeBSD server later.

1 Answer 1


I'm not sure what you mean by programmatically, so here are some ideas.

These days, all output targets PostScript, which is itself a language, so you could write your requests in that, but it is a little difficult. (PDF is mostly convertable to PostScript). However, to overcome some limitation of a conversion tool, you can often tweak the PostScript output that it generates.

At the other extreme, there are commands like enscript which takes plain text and converts it to PostScript. Though intended to help print and highlight code like C and perl, you can embed commands within your plain text to change the font, and so on, or include bits of PostScript or images in EPS format.

Amongst the markdown languages, there is reStructuredText which allows you to change fonts and include images. rst2pdf converts it to a pdf.

The oldest typesetting language on Linux, and FreeBSD, is troff, extended under GNU to groff. It is purpose built to allow you to put text anywhere on a piece of paper, and can include PostScript images. The basic commands can be a little hard to master, but there are several macro packages like mm which allow you to create a document fairly simply.

As for real programming, perl, C, java, python, probably all have some sort of library to allow you to generate pdfs to some degree.

  • "Programmatically" as in I have two existing files and I run a script or a program that will combine the two into a predefined layout. I think you've put me on a good path with enscript and troff. I didn't know they existed until now!
    – Allan
    Apr 28, 2020 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .