Pdf Editing: change page size WITHOUT resizing content or rotate page WITHOUT rotating content

Viewed 50

I receive postage labels from a supplier as single page pdf documents. The labels would fit on an A5 sheet but they are presented as a portrait within an A4 page, also in portrait orientation. I would like to be able to print two of these labels per A4 page to cut down on waste.

This can be achieved by rotating the page content without rotating the page itself. Or by resizing the page by swapping the height and width about the content. I am aware that both of these things can result in content being lost, which isn't a problem for my use case. Ideally I'd like a command line application that works on both Linux or Windows machines. Unfortunately, web searches for "rotate" or "resize" pdf will point to the many applications that just rotate or resize pdf pages along with the content which isn't what I want.

Similar questions:

  • With PdfBox: identical use case, see my comments on PdfBox below.
  • With iText: almost identical use case, I explicitly don't want any resizing of the content. See my comments on iText below as well.

Things I have investigated tried:

  • pdftk - too basic
  • ImageMagick - the original image contains transparency and the extent argument results in a visible loss of quality
  • pdfjam - also requires install of Latex and PdfPages. Ideally I'd like something that works on both Windows and Linux.
  • iText7 - the documentation isn't great. Looks like it was completely re-written in the last few years and the Nuget feed makes it clear that previous version, iTextSharp, is EOL. Consequently most of the examples one finds online (including on this site) are out of date. iText7 doesn't let you resize a page. I got as far as saving a document with a new page that was the right size but struggling to copy the content over. I think I could get what I wanted from this but it would take a long time and I'm trying to do something simple.
  • PdfBox - I've already tried one .NET library without success. Looking at the comments to the question I've linked above, this one seems to also have a version issue. I'm trying to do something really simple here, I will try this one if I exhaust all other avenues
  • Gimp - does what I want but I have to fire up the application, point and click quite a few times to rescale the image canvas, set the background and export
  • Screenshot the label from a pdf reader at 100% size and paste into a Word/LibreOffice doc. Sadly this is the most reliable method I have at the moment

I have example labels but they contain the name and address of people I've sent things to, I'd rather not upload them.

1 Answers

Try the command line tool cpdf from here: https://community.coherentpdf.com

cpdf -rotate-contents <angle> in.pdf -o out.pdf

to rotate contents without rotating the page. or...

cpdf -mediabox "100 100 600 500" in.pdf -o out.pdf

(and -cropbox and so on) to change page dimensions without altering content. Chapter 3 of the manual is of relevance.

You can also prepare the file by removing any page rotation whilst counter-rotating the content to leave the visual appearance unchanged:

cpdf -upright in.pdf -o out.pdf
Related