Created at:
Modified at:
Ghostscript notes
Using Ghostscript to manipulate PDF files
Join PDF files with just a simple command:
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
Reference: Putting together PDF files
To generate a file with a subset of its pages, use gs
as well::
$ gs -dBATCH -dSAFER -dNOPAUSE -dFirstPage=5 -dLastPage=10 -sDEVICE=pdfwrite -o output.pdf input.pdf
To compress a PDF (resizing the file size)::
$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dCompatibilityLevel=1.4 -sOutputFile=output.pdf input.pdf
Settings can be /screen
, /ebook
, /printer
and /prepress
,
ranging from low quality images resolution to better quality. I like to use
/ebook
. I could turn a 8 MB PDF into a 276 KB file suitable to be sent to
e-mail.
Editing PDF metadata
(2018-09-27)
There are many ways to edit a PDF metadata, using other programs. See the following two links about simple ways to do that.
How to edit pdf metadata from command line?
Ghostcript PDF Reference & Tips
First, create a file with the desired information. Let's call this file
pdfmarks
::
[ /Title (Document title)
/Author (Author name)
/Subject (Subject description)
/Keywords (comma, separated, keywords)
/ModDate (D:20061204092842)
/CreationDate (D:20061204092842)
/Creator (application name or creator note)
/Producer (PDF producer name or note)
/DOCINFO pdfmark
Now, just call Ghostscript passing both PDF file and the pdfmarks
file as
parameters::
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf no_marks.pdf pdfmarks
Your output.pdf
file will be created with the metadata. :-)