Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: optimize and compress pdf

  1. #1
    Join Date
    Jan 2009
    Beans
    6

    optimize and compress pdf

    List out free packages (which provide command line tool) to compress and optimize pdf files.
    I used pdftk. That compresses only some kbs.

  2. #2
    Join Date
    Jan 2009
    Beans
    6

    Re: optimize and compress pdf

    plz reply

  3. #3
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: optimize and compress pdf

    Quote Originally Posted by vishnuvardan View Post
    List out free packages (which provide command line tool) to compress and optimize pdf files.
    I used pdftk. That compresses only some kbs.
    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.

  4. #4
    Join Date
    Jan 2009
    Beans
    6

    Smile Re: optimize and compress pdf

    Thank you very much kaikob
    It helped me very much.

  5. #5
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: optimize and compress pdf

    Quote Originally Posted by vishnuvardan View Post
    Thank you very much kaikob
    It helped me very much.
    Your most welcome. I'm glad that did the job.

  6. #6
    Join Date
    Feb 2006
    Beans
    24

    Lightbulb Re: optimize and compress pdf

    Quote Originally Posted by vishnuvardan View Post
    List out free packages (which provide command line tool) to compress and optimize pdf files.
    I used pdftk. That compresses only some kbs.
    Debian has released an update to pdftk that compresses correctly as version 1.41+dfsg-9. When next Ubuntu resyncs with Debian, you'll be able to compress PDFs.

  7. #7
    Join Date
    Feb 2011
    Beans
    2

    Re: optimize and compress pdf

    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).

  8. #8
    Join Date
    Jun 2011
    Beans
    1

    Re: optimize and compress pdf

    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

  9. #9
    Join Date
    Mar 2007
    Beans
    112
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: optimize and compress pdf

    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) :
    Code:
    sudo apt-get install poppler-utils ghostscript
    Then you need to save the following script :

    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"
    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:
    /path/to/optimize_pdf.sh -s input.pdf -o output.pdf
    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.3M
    Last edited by MrEgg; June 28th, 2011 at 07:54 AM.
    Sandy Bridge i5-2500, Asus P8Z68-V Pro

  10. #10
    Join Date
    Feb 2011
    Beans
    2

    Re: optimize and compress pdf

    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.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •