views:

48

answers:

2

I've got a PDF file which is exactly 1/5 of the size of an A4 page, and a script to convert it into a single A4 page by appending it repeatedly. The problem is that ImageMagick only works with bitmap graphics, and my PDF contains text and detailed vector graphics. The result is therefore loss of text data, much bigger file size, and worse print output.

I'd like to be able to do the same as the line convert -density 1200 $pdf_file $pdf_file $pdf_file $pdf_file $pdf_file +append $a4_file without rasterising the vector graphics.

+1  A: 

OK, I've an idea how this could work, but I don't have the possibility to test it at the moment.

Now consider these three commands (would need Unix-ification if you're not on Windows):

 gswin32c ^
    -sDEVICE=pdfwrite ^
    -o p1.pdf ^
    -dFIXEDMEDIA ^
    -sDEFAULTPAPERSIZE=a4 ^
    -r600x600 ^
    -dDEVICEWIDTHPOINTS=842 ^
    -dDEVICEHEIGHTPOINTS=595 ^
    -c "<</PageOffset [0 0]>> setpagedevice" ^
    -f c:/path/to/first.pdf

 gswin32c ^
    -sDEVICE=pdfwrite ^
    -o p2.pdf ^
    -dFIXEDMEDIA ^
    -sDEFAULTPAPERSIZE=a4 ^
    -r600x600 ^
    -dDEVICEWIDTHPOINTS=842 ^
    -dDEVICEHEIGHTPOINTS=595 ^
    -c "<</PageOffset [168.4 0]>> setpagedevice" ^
    -f c:/path/to/second.pdf

 gswin32c ^
    -sDEVICE=pdfwrite ^
    -o p3.pdf ^
    -dFIXEDMEDIA ^
    -sDEFAULTPAPERSIZE=a4 ^
    -r600x600 ^
    -dDEVICEWIDTHPOINTS=842 ^
    -dDEVICEHEIGHTPOINTS=595 ^
    -c "<</PageOffset [336.8 0]>> setpagedevice" ^
    -f c:/path/to/third.pdf

Barring any mis-calculation on my part, these "print" your first 3 PDFs onto an A4 landscape medium, but shifting the page offset for each one by 'n*(1/5 of the landscape width)' points, starting with n=0. (A4 is 842x595 points). You get the idea...

Now you'll have 3 (and later: 5) new PDF files without any additional bitmap graphics.

Your job remains now to use pdftk (which you seem familiar with) to overlay these 3 (5) PDF pages over each other.

Please give some feedback if this works for you. (And don't let the Black Hole escape :-) ).

pipitas
Looks like an interesting solution, but I was hoping for something simpler.
l0b0
+1  A: 

pdftk and pdfnup are really most excellent!

Pseudocode version of the finished script:

for each file:
    inkscape --export-pdf
    pdftk (pdf-file x 5) cat output 5.pdf
    pdfnup 5.pdf --nup 5x1 --paper a4paper --orient landscape --outfile {recto,verso}.pdf

pdftk R=recto.pdf V=verso.pdf cat R1W V1E output bookmark.pdf
l0b0
Oh? pdfnup works now reliably? I had played with it a few years ago, but it didn't work as needed. Had forgotten about it in the meantime. Thanks for mentioning it, I need to get up to date on it again.
pipitas
Just to be sure: are we talking about... - ...the Python-based pdfnup by Dhino Gherman? (I am) - ...or the pdfTeX/pdfpages-based pdfnup by David Firth?
pipitas
It's the second one, installed with the Ubuntu package "pdfjam".
l0b0