4

I am using (PDF)LaTeX to make a document, and I also need to embed already existing PDF documents in it. The problem is that I have PDF documents in several different page sizes (letter, a4, etc) and I want to compile all of them into a single b5 PDF document.

If I use the pdfpages package from CTAN, all hyperlinks from the original PDFs are removed. So I tried to do it with GhostScript.

This sounds like something normal to do but I have failed to find a working solution. I have, in the meanwhile, read a few question and answers, but failed to figure out what I am doing wrong and what I am missing.

This doesn't seem to address my problem of scaling.

Neither does that.

This seems to go in the right direction but I couldn't make use of the information :-(.

To make the problem easier, let's just try to resize a single PDF so that:

  • its contents are scaled to fit the page
  • the new page has the size I want

Sounds easy, and it is easy to do, for example with pdfjam:

pdfjam --outfile b5-foo.pdf --paper b5paper foo.pdf

Now the problem with this is that pdfjam throws away hyperlinks. From its website:

A potential drawback of pdfjam and other scripts based upon it is that any hyperlinks in the source PDF are lost.

This must be because it seems to use pdfpages mentioned above.

Unlike pdfjam, GhostScript keeps hyperlinks. However, it either:

  • crops the original when I downscale; or
  • does not put the scaled content on a page of the size I need -- instead, I get a page that seems to be scaled down, while keeping the original aspect ratio.

This is what I have installed:

$ gs --version
9.21

(Installed on Linux)

This is how I can use GhostScript to crop the content:

gs -dBATCH -dNOPAUSE \
    -sDEVICE=pdfwrite -dFIXEDMEDIA -sPAPERSIZE=isob5 \
    -o b5-foo.pdf foo.pdf

... and here is how I can use -dPDFFitPage to scale the content but also keep the aspect ratio of the original page size:

gs -dBATCH -dNOPAUSE \
    -sDEVICE=pdfwrite -dFIXEDMEDIA -sPAPERSIZE=isob5 -dPDFFitPage \
    -o b5-foo.pdf foo.pdf

To be even clearer: I seem to get a page that is scaled so that it would fit inside the b5 I am asking for, but it is not b5: it still has the H/W ratio the original (letter) had!

I'd be happy if this can be done just using switches but if I need to use PostScript that's perfectly fine.

Community
  • 1
  • 1

1 Answers1

3

The solution seems to be to use -dPSFitPage instead of -dPDFFitPage. This might have something to do with the PDF files that I am trying to resize. Unfortunately, I cannot share those :-(. When I tried to reproduce this with files that I generated and the problem does not reproduce. I don't know why this is or how I should have known it.

To summarize, using PDF files for both input and output:

  • -dFitPage and -dPDFFitPage give me scaled pages with the original aspect ratio
  • -dPSFitPage gives me scaled content on the page size I request with -sPAPERSIZE="$PAPERSIZE"

This seems to go against what the documentation says.

  • If you are using PDF input, then PSFitPage shouldn't do anything. To be honest I would have thought PDFFitPage would do what you want, and I'm not clear on what its doing that you don't like. You seem to be saying that you want the page scaled to git your new media size, but not preserving the aspect ratio of the original document..... Posting a simple example (source files and command line) would probably help, I can't visualise your problem from the description. – KenS Apr 15 '17 at 14:25
  • @KenS How exactly should I share the source files and the results? –  Apr 15 '17 at 14:57
  • @KenS It might also have to do something with the version of GhostScript I am using; actually, I came to think of trying out `PSFitPage` because this is what was suggested somewhere in the online documentation for GhostScript 9.21. I will add the version to the question. –  Apr 15 '17 at 14:59
  • 1
    @KenS what I don't like is that when I use `PDFFitPage` the page is scaled but it keeps its original aspect ratio (so the page is not b5 even though this is what I ask for exclusively!); when I use `PSFitPage`, it is scaled to fit a page of the exact size I want. –  Apr 15 '17 at 17:23
  • "explicitly" not "exclusively" –  Apr 15 '17 at 17:39
  • Hmm, keeping the aspect ratio is exactly what PDFFitPage (and friends) are supposed to do. The page **is** B5, the content has been rescaled from something else to fit B5, and the scaling is done equally in each direction. Notice that in PostScript and PDF the content is independent of the media size, you can have content that lies off the media, as well (obviously) as white space around the content. So when you change hte media, and ask Ghostscript to fit it, what it does its look at the original media size, and the requested size, and scale minimally to fit. – KenS Apr 15 '17 at 18:47
  • You can do other things if you want to, but scaling the dimensions unequally will give weird results. As regards sharing the files, anywhere public will do, DropBox or whatever. – KenS Apr 15 '17 at 18:47
  • @KenS I did not mean to scale the dimensions unequally, my problem really **was** that I got a PDF with pages of different dimensions in it. I cannot reproduce it with one-page PDF that I generated myself, so now I am starting to suspect the PDFs that I was given.... Since I now have a working solution, I consider this issue closed. –  Apr 16 '17 at 06:19