List out free packages (which provide command line tool) to compress and optimize pdf files.
I used pdftk. That compresses only some kbs.
List out free packages (which provide command line tool) to compress and optimize pdf files.
I used pdftk. That compresses only some kbs.
plz reply
vishnuvardan
I do not know of any package that will compress and optimize pdf files. The command line I suggested in the following thread will reduce pdf file size, but it does so with some loss in quality.
http://ubuntuforums.org/showthread.php?t=1133357
The pertinent setting in the command line is -dPDFSETTINGS. The following site has a table that details the different -dPDFSETTINGS and what they do:
http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm
kaibob
Last edited by kaibob; June 25th, 2009 at 08:45 PM.
Thank you very much kaikob
It helped me very much.
![]()
The best (and the only) free program that i've found myself so far that actually optimises PDF's and can significantly reduce the size without compressing images or any other lossy operations is the PDFCompressor released in 2005. Apparently newer versions are not free. I run it in WINE to compress PDF files produced by Mac OS Preview application (when merging PDF's or deleting pages in Preview, the size can sometimes increase twice).
There's a nice tool called "Multivalent" on Sourceforge, that has this feature. It's especially useful if you use pdftk to cat a lot of pdf-documents based on the same base document, as it can remove duplicates of images and such in the final document.
It's written in java, and for the past couple of years I've been using it with the following command from the CLI:
java -cp "[Path]\Multivalent.jar tool.pdf.Compress [MyPDFFile]"
It reduces my pdf-file from around 500 MB to 1 MB, as I've concatenated around 500 documents containing the same image as background.
I wish that this feature would be incorporated in pdftk. I don't have the means to do it myself
Best regards,
Kolben
I came across this page (French) which contains the following method and script. I am not the author of the script and don't deserve any credit for it. I am just translating into English.
First of all, you need to install poppler-utils and ghostscript (most likely, you already have ghostscript) :
Then you need to save the following script :Code:sudo apt-get install poppler-utils ghostscript
Save the script as optimize_pdf.sh, and give it execute permission. Using Terminal, cd to the directory holding your input pdf. To shrink the pdf, type in :Code:#!/bin/bash DPI=150 PDF_DESTINATION="" help() { echo "optimize_pdf help" echo "-h : show this help" echo "-d : (optional) output pdf document resolution, by default : 150" echo "-s : pdf source file, this file must exist" echo "-o : pdf output file" } full_path() { if [ -z $1 ]; then exit; else if [ `expr substr ${1:-a} 1 2` != "/" ]; then FULL_FILE=`pwd`"/"$1 fi fi echo $FULL_FILE } isNumeric(){ echo "$@" | grep -q -v "[^0-9]" ;} while getopts "s:o:d:h" flag do case $flag in #Source : source file "s") PDF_FILE=`full_path $OPTARG` if [ ! -e $PDF_FILE ]; then echo "Please provide a valid source file" exit=1 fi ;; #Output : output file "o") PDF_DESTINATION=$OPTARG ;; #Dpi : desired resolution "d") if [ -z `isNumeric $OPTARG` ]; then DPI=$OPTARG else echo "Please provide a numeric value for your DPI" exit=1 fi ;; "h") exit=1 ;; esac done #Is there a target file? if [ -z $PDF_DESTINATION ]; then echo "Please provide a file name for output" exit=1 fi #At least one error, we're not going any further if [ $exit ]; then help exit fi pdftops \ -paper match \ -nocrop \ -noshrink \ -nocenter \ -level3 \ -q \ "$PDF_FILE" - \ | ps2pdf14 \ -dEmbedAllFonts=true \ -dUseFlateCompression=true \ -dOptimize=true \ -dProcessColorModel=/DeviceRGB \ -dUseCIEColor=true \ -r72 \ -dDownsampleGrayImages=true \ -dGrayImageResolution=$DPI \ -dAutoFilterGrayImages=false \ -dGrayImageDownsampleType=/Bicubic \ -dDownsampleMonoImages=true \ -dMonoImageResolution=$DPI \ -dMonoImageDownsampleType=/Bicubic \ -dDownsampleColorImages=true \ -dColorImageResolution=$DPI \ -dAutoFilterColorImages=false \ -dColorImageDownsampleType=/Bicubic \ -dPDFSETTINGS=/prepress \ - "$PDF_DESTINATION"
where input.pdf is the name of your input file and output.pdf the name of your output file. For me, it reduced an original 8-page grayscale document from 4.4M to 1.3MCode:/path/to/optimize_pdf.sh -s input.pdf -o output.pdf
Last edited by MrEgg; June 28th, 2011 at 07:54 AM.
Sandy Bridge i5-2500, Asus P8Z68-V Pro
Thanks MrEgg!
I compared the command from the link you have suggested with the PDFCompressor.
A 3.4 MB PDF file was losslessly compressed to 1 MB by the command you've found, and to 2.8 MB by PDFCompressor.exe.
However, i should probably mention that i obtained this test file by removing one page from a 280 KB file with Preview.app, which resulted in a 3.4 MB file.
Bookmarks