Shrinking a PDF from the command line: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is a simplified version of the method used in [[Web optimised PDF]].
This is a simplified version of the method used in [[Web optimised PDF]].


That article shows a Perl script, a rather long one at that, to accomplish the task. The actual shrinkage is accomplished by the use of <tt>pdf2ps</tt> and <tt>ps2pdf</tt>, which are utilities which come with ghostscript.
That article shows a Perl script, a rather long one at that, to accomplish the task. The actual shrinkage is accomplished by the use of '''pdf2ps''' and '''ps2pdf''', which are utilities which come with ghostscript.


My reading of the man page for '''pdf2ps''' and a [http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm web reference] for '''ps2pdf''' suggest that the first step, converting to a PostScript file, does not involve any compression. It is only in the conversion back to PDF that various settings allow for shrinking the size of the resulting file.
My reading of the man page for '''pdf2ps''' and a [http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm web reference for '''ps2pdf'''] suggest that the first step, converting to a PostScript file, does not involve any compression. It is only in the conversion back to PDF that various settings allow for shrinking the size of the resulting file.


===pdf2ps===
===pdf2ps===
Let's say you have a file, '''myfile.pdf''', created by Scribus. About the only setting in pdf2pdf to consider is the language level,
Let's say you have a file, '''myfile.pdf''', created by Scribus. About the only setting in '''pdf2ps''' to consider is the language level,
<pre>
<pre>
pdf2ps -dLanguageLevel=3 myfile.pdf
pdf2ps -dLanguageLevel=3 myfile.pdf
Line 14: Line 14:


===ps2pdf===
===ps2pdf===
On the return trip, there are many settings to consider, but for simplicity's sake you might using just one:
On the return trip, there are many settings to consider, but for simplicity's sake you might try using just one:
<pre>
<pre>
ps2pdf -dPDFSETTINGS=/screen myfile.ps
ps2pdf -dPDFSETTINGS=/ebook myfile.ps
</pre>
</pre>
Or, to avoid deleting your original '''myfile.pdf''', you might put:
Or, to avoid deleting your original '''myfile.pdf''', you might put:
<pre>
<pre>
ps2pdf -dPDFSETTINGS=/screen -sOutputFile=myshrunkenfile.pdf myfile.ps
ps2pdf -dPDFSETTINGS=/ebook -sOutputFile=myshrunkenfile.pdf myfile.ps
</pre>
</pre>
The '''-dPDFSETTINGS''' option has a number of prebuilt subsettings which you will find on the above referenced webpage. Choices are '''/screen''', '''/ebook''', '''/prepress''', and '''/printer'''.
The '''-dPDFSETTINGS''' option has a number of prebuilt subsettings which you will find on the above referenced webpage. Choices are '''/screen''', '''/ebook''', '''/prepress''', and '''/printer'''. I think you will find that using the '''/ebook''' value will give a very good compression, but better resolution than using '''/screen'''.


If you go to the reference page, you will see a ''very'' large number of other choices for things such as image compression that you may wish to try out, but just using the '''/screen''' setting for an example 126KB file produced a 594KB PostScript file, then a final PDF of only 21KB, so only about 1/6 the size of the original. As always, check the quality of the final to see if it's adequate for your needs.
If you go to the reference page, you will see a ''very'' large number of other choices for things such as image compression that you may wish to try out, but just using the '''/screen''' setting for an example 126KB file produced a 594KB PostScript file, then a final PDF of only 21KB, so only about 1/6 the size of the original. As always, check the quality of the final to see if it's adequate for your needs.

Latest revision as of 19:56, 13 April 2020

This is a simplified version of the method used in Web optimised PDF.

That article shows a Perl script, a rather long one at that, to accomplish the task. The actual shrinkage is accomplished by the use of pdf2ps and ps2pdf, which are utilities which come with ghostscript.

My reading of the man page for pdf2ps and a web reference for ps2pdf suggest that the first step, converting to a PostScript file, does not involve any compression. It is only in the conversion back to PDF that various settings allow for shrinking the size of the resulting file.

pdf2ps

Let's say you have a file, myfile.pdf, created by Scribus. About the only setting in pdf2ps to consider is the language level,

pdf2ps -dLanguageLevel=3 myfile.pdf

which will create myfile.ps, and will be larger than the original PDF.

ps2pdf

On the return trip, there are many settings to consider, but for simplicity's sake you might try using just one:

ps2pdf -dPDFSETTINGS=/ebook myfile.ps

Or, to avoid deleting your original myfile.pdf, you might put:

ps2pdf -dPDFSETTINGS=/ebook -sOutputFile=myshrunkenfile.pdf myfile.ps

The -dPDFSETTINGS option has a number of prebuilt subsettings which you will find on the above referenced webpage. Choices are /screen, /ebook, /prepress, and /printer. I think you will find that using the /ebook value will give a very good compression, but better resolution than using /screen.

If you go to the reference page, you will see a very large number of other choices for things such as image compression that you may wish to try out, but just using the /screen setting for an example 126KB file produced a 594KB PostScript file, then a final PDF of only 21KB, so only about 1/6 the size of the original. As always, check the quality of the final to see if it's adequate for your needs.