Recently I wanted to print a large image in it’s original size. As I don’t have a plotter, but only a normal printer whose maximum page size is A4 and the image was way larger than that, I wanted to print it in parts and just stitch the pages together manually.
Surprisingly the applications that I tried didn’t have any support for what I thought would be a common problem.
After some searching I found an application called PosteRazor which basically does what I want:
It takes an image as an input and generates a pdf that consists of several pages, each of which contains a part of the image. By sending that pdf to the printer and printing it in it’s original size you can just cutoff the unnecessary borders and glue the pages back together.
That’s a great idea, but there were some things I didn’t like, eg. you can specify borders, but instead of getting a margin around each page, it seems to substract the border length from the page dimensions.
PosteRazor is ancient by software standards - it’s still hosted by sourceforge and I found an discussion from 2008 discussing this exact issue.
Additionally, I would have preferred a console application for easier scripting, but that’s just me.
I remember a time when I would have dreaded writing an application that creates PDFs, but today - thanks to great libraries like PDFKit - this is very doable and so I was tempted to just try that.
For the image manipulation part I’ve used Sharp which I also found very nice to use.
The app, which I have very creatively called img2splitpdf is available on github in case you are interested.
It works in the following way:
First it reads in the image data via stdin.
Then it splits the image into parts by calculating the max size of each part by subtracting the margins from the page size.
It tries to calculate the physical filesize using the image size and it’s pixel per inch. If the latter is not correctly set, you can set it manually via --ppi and applies a scaling according to this factor.
Then it creates a separate page for each image and writes the pdf to stdout.
As a future reference for myself:
git clone https://github.com/8/img2splitpdf
cd img2splitpdf
bun i
# split the image
bun run main.ts > out.pdf < in.png
# or override the pixel per inch manually
# bun run main.ts --ppi 128 > out.pdf < in.png
# print the pdf
lp -o raw ./out.pdf
The margin and the page size are currently hardcoded, but given that I have only A4 paper I don’t think I’ll need to change them anytime soon. If that’s not you, the app is very small and hackable and you could just edit it yourself.