Add white border to PDF (change paper size)

I need to change a given PDF from A4 ( 210mm*297mm

) to 216mm*303mm

.

An additional 6mm for each dimension should be set as a 3mm white border on each side. The original content of the PDF pages should focus on the output pages.

I tried with convert

:

convert in.pdf -bordercolor "#FFFFFF" -border 9 out.pdf

      

This gives me exactly what I want, but I lose very much the sharpness of the original images in the PDF. All this is blurry.

I also checked with

convert in.pdf out.pdf

      

which doesn't make any changes at all other than screwing up the images.

So I tried Ghostcript but didn't get any results. The best approach I've found so far from the German side:

gs -sOutputFile=out.pdf -sDEVICE=pdfwrite -g6120x8590 \
-c "<</Install{1 1 scale 8.5 8.5}>> setpagedevice" \
-dNOPAUSE -dBATCH in.pdf

      

but I get the error: / typecheck in -. postinstall -.

+3


source to share


3 answers


Offsetting content on media isn't particularly difficult, but it does mean changing the flow of PDF content, from which most PDF processing packages are not excluded.

The code you cite above won't really work, it leaves garbage on the operand stack and PLRM explicitly states that it is followed by an implicit initgraphics

one that will reset all standard parameters anyway.

Instead, you could try setting up a procedure /BeginPage

to translate the source, which will probably work:



<</BeginPage {8.5 8.5 translate} >> setpagedevice

      

Please note that you are not just manipulating the original PDF; Ghostscript takes the original PDF, interprets it as graphics primitives, and then concatenates those primitives again into a new PDF, which has implications ... For example, if a DCT image is encoded (JPEG) in the original, it will be decompressed before being sent to the output file. You probably don't want to reuse the DCT encoding, as this will introduce visible artifacts.

A simple alternative, but using a few processing steps and therefore more room for problems, is to convert the PDF to PostScript using the device first ps2write

, specifying the size of your media, and a switch -dCenterPages

, then use pdfwrite

to convert the resulting PostScript to a new one PDF file.

+2


source


By default Imagemagick converts input PDF files to 72dpi images. This is an awfully low resolution, as you experienced in the first place. Imagemagick's output is always a bitmap, so if your PDF input text was text, it won't be anymore.

If you don't mind the larger PDF, you can simply increase the ratio. Imagemagick examines the original PDF with an option -density

like:



convert -density 600 in.pdf -bordercolor "#FFFFFF" -border 9 out.pdf

      

I used 600 because it's a sweet spot that works well for OCR. I repeat, trying 300, 450, 600, 900 and 1200 and pick the best one that doesn't get cumbersome.

+1


source


Instead

-g6120x8590 \
-c "<</Install{1 1 scale 8.5 8.5}>> setpagedevice"

      

(which is not correct) you should use:

-g6120x8590 \
-c "<</Install{8.5 8.5 translate}>> setpagedevice"

      

or

-g6120x8590 \
-c "<</Install{3 25.4 div 72 mul dup translate}>> setpagedevice"

      

(which allows Ghostscript to compute itself " 3mm == 8.5pt

")

0


source







All Articles