21st May 2008, 12:19 am
pdf is a document format. there are occasions where I find it easier to work with one large document rather than several single documents (most recently, while working with several spec sheets for electronic components), the following command will join two or more *.pdfs into a single document using ghostscript.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf INPUT01.pdf INPUT02.pdf ...
-dBATCH - exit after last file
-dNOPAUSE - no pause after page
-q - “quiet”, fewer messages
-sDEVICE=<devname> - select device, in this case the pdf writer
-sOutputFile=<file> - select output file
the following were not, but could be, included:
-g<width>x<height> - page size in pixels
-r<res> - pixels/inch resolution
4th May 2008, 01:03 am
pdf is a document format. on the occasion where it is easier to reference an image rather than the full document, the following command will convert the pdf.
convert -density 96x96 -trim INPUTFILE.pdf OUTPUTFILE.jpg
-density is the image density in pixels per square inch
-trim will trim the image edges
the output will be in the form of OUTPUTFILE-#.jpg, where # is an increasing “page” number.
this command will also work for OUTPUTFILE.png, OUTPUTFILE.gif, et. al..
also, imagemagick uses ghostscript to convert, so the quality of the final images will only be as good as ghostscript can provide.
10th September 2007, 11:51 pm
I had a postscript document that simply did not want to come out correctly, the offsets were such that the page content was going well off the visible area.
the following vile hack is one solution:
cat <<EOF>offsetfix.ps
%!PS-Adobe-2.0
<<
/PageOffset [ 16 -52]
/Margins [0 0]
/.HWMargins [0 0 0 0]
>>
setpagedevice
EOF
gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite \
-dOptimize=true \
-sOutputFile=output.pdf \
offsetfix.ps input.ps
granted, one could cat the snippit in offsetfix.ps with the original document, but as I’m not sure what else may be using it, I’d rather not.
this also has the advantage of being a bit more portable, albeit rather ugly when compared to the original:
ps2pdf input.ps output.pdf