How to change the margins of PDF files while keeping the page size (”scale the content”)?

August 2nd, 2008 by matthias

This is on how to achieve that on Linux. There are multiple alternatives, but none of them proved perfect yet. Let’s start.

Alternative 1: using pstops

The task can be performed with pstops (whereof psnup is a simplified frontend).

  1. Convert your PDF file to a PS file, by printing to a file in Adobe Reader, or by using pdf2ps (Ghostscript-based) or pdftops (xpdf-based).
  2. Use pstops to adjust the marginspstops -p a4 "L@.9(1cm,1cm)" in.ps out.ps

    On mounting pages: here, the the task is to mount two A4 pages in A5 format on one A4 page, guaranteeing page margins of 3cm at left and right and 2cm at top and bottom. We need a width of 150mm and a height of 257mm. To scale 297mm (A4 height) to 150mm, use factor 0.505. Such n-up mounting together with freestyle adjustment of margins is not possible ith psnup, which has a simpler user interface.

    pstops -p a4 "2:0L@.505(18cm,2cm)+1L@.505(18cm,14.85cm)" in.ps out.ps

  3. Convert the PS file back to PDF by using pdftops.

The problem with psnup (from PSUtils Release 1 Patchlevel 17) and also of its frontend psnup is that it converts fonts to bitmap fonts (Adobe Type 3). This can be detected as rastered fonts when viewing the PDF file with Adobe Reader. It generates somewhat lower print quality, but is still acceptable. What is not acceptable (with respect to file size) is that pstops converts the whole file to an image if it has no idea how to treat it.

To debug pstops and psnup output, you can use the -b option, which will mark out the original pages’ borders.

Alternative 2: Using Adobe Reader and printer margins

This has not yet been worked out, but might be possible. When printing (to a file or otherwise) Adobe Reader will fit the pages into the printable area of the selected printer. Now the idea would be to choose the special printer “Custom …”. This allows you to enter a lp print command. Per the lp documentation, CUPS lp understands options to set the margins. For 2cm at top and bottom and 3cm at left and right, use this command:

/usr/bin/lp -o page-top=57 -o page-bottom=57 -o page-left=85 -o page-right=85

However, this currently does not work our, for an unknown reason. It does not change anything, i.e. the document is printed as if you selected “Page scaling: none” instead of “Page scaling: fit to printable area”. If this command is not possible, another alternative would be to set up a printer definition with exactly the margins you desire, in a way that lets you change these margins easily.

If you just need “larger” margins around your page (without exact measures), you can do the following:

  1. Print the file with Adobe Reader to a PS file. Use the option “Page scaling: fit o printable area”. Try several different printers including the “Custom …” special printer to find one that adds margins of the same size all around the page. This step will generate a PS file with larger margins than the original PDF file had, even though this is not correctly shown in the preview of Adobe Reader 8.1.1.
  2. Convert the file to a PDF file by using ps2pdf.
  3. Repeat from step 1 with your new PDF file until the margins are large enough for you.

This method has the obvious disadvantage of not allowing to specify the margins exactly, but at least the file retains vector fonts and graphics (unlike whenusing pstops, see above).

If you need the margin adjustents in combination with Adobe Readers n-up printing (e.g. 2 pages per sheet), and if you can adjust the margins in your source file (before generating the initial PDF), you can do the following: adust the margins in the original file so that, after the n-up scaling, these margins together with the selected printer’s margins, result in the margins you desire. When printing one two pages A4 on one sheet A4 with the special prnter “Custom …” in Adobe Reader 8.1.1, the following margins are used (measured in the output A4 page):

  • left 5,25mm
  • right 13,71mm
  • top 6,59mm
  • bottom 6,59mm (probably)

Alternative 3: Using Adobe Reader and printing the “current view”

Another alternative:

  1. Use Adobe Reader to print your page to a large sheet without scaling.
  2. Use ps2pdf to re-destill the PS file to PDF.
  3. Open the new PDF file in Adobe Reader and choose an appropriate view. Use the “print current view” option in Adobe Reader to print exactly thet view.
  4. Re-destill the PS output to PDF.
  5. That way, you can even achieve n-up mounting: say you generated to pages, each with content in different places and the rest white space. You can overlay these pages on top of each other using pdftk with the background option.

Alternative 4: Using ghostscript

The following would constitute an elegant solution: freely adjustable margins and vector fonts and images, and avoiding the GUI hassles. Sad enough, it does not work yet. The idea come from this thread.

gs \
  -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
  -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" \
  -dSubsetFonts=true -dEmbedAllFonts=true \
  -sPAPERSIZE=a4 -sOutputFile="out.pdf" \
  -c "<</BeginPage{0.5 0.5 scale -90 rotate -2384 0 translate}>> setpagedevice" \
  -f in.pdf

The instruction works, apart from the important -c option part, which adds a postscript command. This instruction would also work with PDF files.

Posted in Acrobat Reader, DTP, Sprache: Englisch, alle Artikel | No Comments »

How can I combine two PDF files so that they are “overlayed” one to the other?

July 21st, 2008 by matthias

This might become necessary if you want to add content to an already existing PDF file, e.g. when doing pre-press work for flyers etc.. For example, you might resize one PDF file to have additional place on the page, and put other content into that free space.

Get yourself two PDF files to overlay on each other, both of the same page size (else automatic resizing is employed), and both one-sided.

Then use this command to generate the combined PDF file with overlays:

pdftk file1.pdf background file2.pdf output out.pdf

Posted in Acrobat Reader, DTP, Sprache: Englisch, alle Artikel | No Comments »

How can I place a PDF file on a bigger, custom-sized page, with free choice of placement?

July 21st, 2008 by matthias

You might open the PDF file in Adobe Reader and print it there to a Postscript file (setting page size to “Custom…” and choosing a bigger than current), but this does not allow free placement, instead Adobe Reader always centers the output on the paper.

Instead, use xpdf. Start it and set the desired print page output size simulteneously:

xpdf -paperw 3444 -paperh 4252 -z page infile.pdf

xpdf expects the sized in Postscript points: 1 point = 127360 mm = 352.7 µm. Sad enough, xpdf also centers the output on the page.

But we have another trick: calculate a page size where you can cut out your desired page size after the content gets centered on it. Generate a PDF with that size using either xpdf or Adobe Reader, printing to file with them and re-destilling to a PDF file. Then, open it in Adobe Reader and bring place the view (i.e. what you see on your screen) exactly so that it covers the page size you want the document to have. You need to set the zoom level for that (which is also possible in 0.01% steps!).

Then print in Adobe Reader to a Postscript file and select “current view”. Adobe Reader informs you about the size of the view in the print preview, so that you can adjust your settings.

And to conclude, destill the Postscript file again to PDF using ps2pdf.

Posted in Acrobat Reader, Sprache: Englisch, alle Artikel | No Comments »

How can I “magnify” a PDF document with DIN A4 pages to another one with DIN A3 pages?

June 5th, 2008 by matthias

Use Adobe Reader for that (here on Linux, but you could use another free Ghostscript based destiller on Windows, e.g. the PDF pseudo printer PrimoPDF).

  1. Open the document in Adobe Reader.
  2. Open the dialog “File -> Print …”.
  3. Select the printer “Custom …”, and in the combobox that appears at the right border of the dialog, select DIN A3 as paper size (you could also enter 420×297mm as custom paper size for this printer, or use a physical printer with both modes).
  4. Select “Page scaling: Fit to printable area”, and if necessary “Auto Rotate and Center”.
  5. Select “Print to file”, and select a file to print to.
  6. Press “OK”.
  7. The resulting file is a postscript file. The page size of a postscript file can be auto detected, or manually set. Here, re-destilling to PDF with ps2pdf gets the page size wrong (it uses DIN A4). Therefore, open the document in kghostview and print it from there to a PDF file (it has correct page size auto detection, see the menus).

One can probably use ps2pdf when telling it about the desired page size explicitly, but I haven’t tested that yet:

ps2pdf -sPAPERSIZE=a3 file.ps

Posted in Acrobat Reader, DTP, Sprache: Englisch, alle Artikel | No Comments »

How can I print out a large page in a PDF document, tiled on multiple small pages, using Acrobat Reader on Linux?

June 5th, 2008 by matthias

Acrobat Reader has no own function to print “tiled on multiple pages”, but there is a trick: use the function to print the “current view”, i.e. current screen content. After that, move the view one tile on by clicking beneath the slider in the scrollbar, and print the next view.

One can combine that with “print to file”, then re-destill the resulting postscript files to PDF files using ps2pdf, and combine the resulting PDF files using “pdftk input.[1-9].pdf cat output output.pdf” (or similar). This results in a tiled version of the document that can be printed out after that without hassle at any printer (e.g. in copy shops etc.).

This mode is also the solution to the non-working “tile” and “print on multiple pages” options in OpenOffice.org Draw 2.4, which always use portrait orientation for the tiles, regardless of the orientation you use in the printer. Therefore, the OOo internal tile functions cannot be used if you created something with the intention to tile it with
landscape A4 paper (e.g. a 1140×297mm page in OOo Draw).

Posted in Acrobat Reader, OpenOffice, Sprache: Englisch, alle Artikel | No Comments »

How can I mount 4 flyers (A6 size) onto an A4 sheet for printing them out?

May 8th, 2008 by matthias

What you want is placing the four flyers in 2×2 format on a sheet of A4 paper, the way they match that paper size, without any additional borders around the A4 page or between the flyers.

Therefore, when designing the flyers in OpenOffice.org Draw, you cannot use its “tile” option for printing out, as the page margins of the original flyer will get collapsed. Also, you cannot use Adobe Reader’s “multiple pages per sheet” printing option, as there is no way to eliminate the printer’s border around the whole page.

However, on Linux there is a nice tool psnup. What to do: Export your flyer to a PDF file. If you use OOo, that’s a built-in function. Then create a PDF file with four flyers, each rotated by 90°, from that. It’s difficult to use unrotated pages in A6 landscape paper size as input to psnup, as the “-l”, “-s” and “-f” options are not well documented and have unprecedented effects. So we use pdftk to rotate the pages beforehand. The command to use:

pdftk flyer.pdf cat 1E 1E 1E 1E output flyer.fourpages.pdf;

Now we need to generate PostScript, as psnup operates on that. To convert to from PDF to PostScript, one cannot use “pdftops -paperw 298 -paperh 421 flyer.fourpages.pdf” (as text is converted to images) and also not “pdf2ps flyer.fourpages.pdf;” (as this crashes). Therefore, print with Adobe Reader, using “Custom” printer, and the options “Choose paper source by PDF page size” and “Print to File”.

Now we can use psnup and after that, create a PDF again:

psnup -H 14.85cm -W 10.5cm -h 29.7cm -w 21cm -d -4 flyer.fourpages.ps flyer.4nup.ps;
ps2pdf flyer.4nup.ps;

To conclude, you can perhaps (if necessary at all) reduce the size of the PDF file to 10% by printing it in Adobe Reader to a PostScript File and converting to PDF again with ps2pdf.

The option “-d” draws a box around each of the four mounted pages, remove for production use, it’s for diagnostics only. And another note out of scope: note that the -s option expects a coefficient (0 to 1), 1 meaning to scale at 100%.

Posted in Acrobat Reader, DTP | No Comments »

Woran kann es liegen wenn eine PDF-Datei nicht korrekt aus Acrobat Reader gedruckt werden kann?

May 2nd, 2008 by matthias

Symptome: PDF-Datei mit eingebetteten Fonts mit Custom Encoding. Statt Buchstaben korrekt zu drucken wird jeder Buchstabe durch »Ö« ersetzt. Lösung: man schalte die Option »Save Printer Memory« im Druckdialog von Acrobat Reader ein. Sie bewirkt eigentlich, dass für jede Seite die benötigten Fonts auf den Drucker geladen werden statt einmal alle Fonts für das Dokument. Für Drucker die keine Zwischenspeicherung von Fonts beherrschen ist das evtl. die Lösung damit der Drucker korrekte Fonts zum Drucken zur Verfügung hat.

Posted in Acrobat Reader | No Comments »

Wie kann ich eine in A4 Querformat gesetzte PDF-Datei (PDF-Seiten haben Querformat) so in 4 NUP drucken dass die Seiten die korrekte Reihenfolge haben wenn man sie in Zeilen bzgl. Querformat statt Hochformat anordnen will?

May 2nd, 2008 by matthias

Einfachste Lösung:

  1. psnup -f -4 infile.ps outfile.ps;

Direkt auf PDF-Dateien:
Statt 1,2,3,4 muss die Reihenfolge sein 2,4,1,3 (Start mit 2, dann wiederholend +2,-3,+2,+3). Also kann man die Seiten wie folgt umordnen:

  1. pdftk input.pdf cat 2 4 1 3 6 8 5 7 10 12 9 11 14 16 13 15 18 20 17 19 22 24 21 23 26 28 25 27 30 32 29 31 34 36 33 35 38 40 37 39 42 44 41 43 46 48 45 47 50 52 49 51 54 56 53 55 58 60 57 59 62 64 61 63 66 68 65 67 70 72 69 71 74 76 73 75 78 80 77 79 82 84 81 83 86 88 85 87 90 92 89 91 94 96 93 95 output output.pdf

Konkretes Beispiel:

  1. pdftk BTF.Tour22.pdf cat 3-95 output BTF.Tour22.S3-95.pdf;
  2. pdftk BTF.Tour22.S3-95.pdf cat 2 4 1 3 6 8 5 7 10 12 9 11 14 16 13 15 18 20 17 19 22 24 21 23 26 28 25 27 30 32 29 31 34 36 33 35 38 40 37 39 42 44 41 43 46 48 45 47 50 52 49 51 54 56 53 55 58 60 57 59 62 64 61 63 66 68 65 67 70 72 69 71 74 76 73 75 78 80 77 79 82 84 81 83 86 88 85 87 90 92 89 91 94 96 93 95 output BTF.Tour22.S3-95.for4nup.pdf

Und dann in 4nup umwandeln, am besten durch Drucken in Acrobat Reader in eine PDF-Datei mit Einstellung 4nup. Man sollte nicht aus OOo Writer direkt in 4nup drucken weil dann ggf. Seitenbereiche abgeschnitten werden.
Wenn sowohl Acrobat Reader als auch xpdf/kpdf Probleme mit Schriftarten beim Drucken dieser Dateien haben liegt es nicht an pdftk! Am besten dann grafisch drucken (z.B. nach Öffnen mit GIMP).

Posted in Acrobat Reader, DTP | No Comments »

Wie kann ich eine PDF-Datei mit Seiten in A4 Querformat in eine mit Seiten in A4 Hochformat umwandeln? Bzw. wie drucke ich unter Linux ein PDF-Dokument mit einer Seite A4 im Querformat auf Papier in A4 im Hochformat?

May 2nd, 2008 by matthias

Einfachste Lösung: Seiten drehen mit pdftk (siehe Optionen zum cat-Befehl). Beispiel:

  1. pdftk BTF.Tour22.final.pdf cat 1-2W 3-endN output BTF.Tour22.PrintMaster.pdf

Dabei muss man wissen welche Seiten im Dokument ggf. schon eine Rotation zugewiesen haben, und welche. Das findet man durch Experimente heraus indem man zuerst einmal alle Seiten auf denselben Rotationswert
(am besten N, d.h. 0°) setzt (wird absolut gemessen, bssherige Rotationswerte werden dadurch also zurückgesetzt).

Einfache Lösung: in Acrobat Reader mit der Funktion »Rotate View« die Seite auf A4 Hochformat drehen und dann drucken mit Normaleinstellungen für Hochformat. Wenn wieder eine PDF-Datei daraus werden drucke man in eine PDF-Datei.

Eine Alternative. Beobachtungen: »Druckausrichtung« in den Druckereinstellungen auf Querformat zu stellen druckt eine leere Seite. In Acrobat Reader gar nichts zu verstellen druckt einen Teil des Inhalts 90° ggü. dem Original verdreht, beginnend oben auf der Seite. In Acrobat Reader unter »File -> Print Setup …« Landscape einzustellen druckt einen Teil des Inhalts 90° ggü. dem Original verdreht, beginnend mitten auf der Seite. Die Lösung: man muss sowohl in Acrobat Reader unter »File -> Print Setup …« Landscape einstellen als auch in den Druchereinstellungen Querformat einstellen.

Lösung über OpenOffice.org Writer: Datei Drucken »in Datei« (mit welchem Drucker ist eigentlich egal, z.B. mit dem für extendedPDF eingerichteten) und wählen als Papierformat des Druckers A4 Portrait. Probleme: Acrobat Reader kann solche Dateien nicht lesen, nur kghostview.

Eventuell eine weitere Möglichkeit: etwas wie:

  1. acroread -toPostScript -landscape file.pdf

Posted in Acrobat Reader, DTP | No Comments »

Wie kann ich in Acrobat Reader 7.0 den Vollbildmodus zur Präsentation so verwenden dass das Fenster tatsächlich auf der gesamten Bldschirmfläche und nicht nur auf einem Teil davon angezeigt wird?

April 30th, 2008 by matthias

Man klicke (in KDE) rechts auf die Titelzeile des Programms und wählt »Erweitert -> Vollbild«. Dann den Vollbildmodus in Acrobat Reader aktivieren.

Posted in Acrobat Reader | No Comments »