Results 1 to 4 of 4

Thread: pdf to png convert not all the pages

  1. #1
    Join Date
    Jul 2006
    Location
    Hungary
    Beans
    76
    Distro
    Ubuntu 12.04 Precise Pangolin

    Question pdf to png convert not all the pages

    At the moment I regularly use Image Magick convert command to convert PDF's to images which is great but I would like to only convert some of the pages in the PDF instead of them all. Im sure the function must be available I just haven't been able to find it even after bashing google for a few days.

    Code:
    convert *full.pdf test%d.jpg
    this is the command I use at the moment.

    Any help would be appreciated
    Ubuntu user number # 29587

    I'm Jet Black, 36 years old. I'm often told I don't look 36, but you shouldn't judge people based on appearances... or on how much hair they have.

  2. #2
    Join Date
    Apr 2006
    Beans
    800
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: pdf to png convert not all the pages

    I don't think you can do that with ImageMagick/convert.
    You can use poppler-utils/pdftohtml to convert the pdf to html where you can set from and to pages.
    Install poppler-utils:
    Code:
    sudo apt-get install poppler-utils
    Example convert pages 1-5 to html:
    Code:
    pdftohtml -f 1 -l 5 -c input.pdf output.html
    Last edited by lykeion; January 27th, 2011 at 11:45 AM.

  3. #3
    Join Date
    Nov 2009
    Location
    East Anglia
    Beans
    417
    Distro
    Xubuntu

    Re: pdf to png convert not all the pages

    Quote Originally Posted by Cowboybebop79 View Post
    At the moment I regularly use Image Magick convert command to convert PDF's to images which is great but I would like to only convert some of the pages in the PDF instead of them all. Im sure the function must be available I just haven't been able to find it even after bashing google for a few days.

    Code:
    convert *full.pdf test%d.jpg
    this is the command I use at the moment.

    Any help would be appreciated
    How about using ghostscript, something like:

    Code:
    gs -dFirstPage=2 -dLastPage=3 -q -dNOPAUSE -dSAFER -dBATCH -sDEVICE=png256 -sOutputFile=output.png -f input.pdf

    H

  4. #4
    Join Date
    Jul 2006
    Location
    Hungary
    Beans
    76
    Distro
    Ubuntu 12.04 Precise Pangolin

    Talking Re: pdf to png convert not all the pages

    Thanks for the suggestions

    in the end I found a blog by Sandeep Sidhu where he had a similar problem of extracting individual pages from a pdf in his solution he created a function in bashrc to shorten the command.


    Code:
    function pdf-extract()
    {
    # this function uses 3 arguments:
    # $1 is the first page of the range to extract
    # $2 is the last page of the range to extract
    # $3 is the input file
    # output file will be named "inputfile_pXX-pYY.pdf"
    gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
    -dFirstPage=${1} \
    -dLastPage=${2} \
    -sOutputFile=${3%.pdf}_page${1}_to_page${2}.pdf \
    ${3}
    }

    @anglican thanks for pointing out that ghostscript can output to image so I combined your suggestion with Sandeep's function and I get this


    Code:
    function pdf-extract()
    {
    # this function uses 3 arguments:
    # $1 is the first page of the range to extract
    # $2 is the last page of the range to extract
    # $3 is the input file
    gs -sDEVICE=jpeg -dNOPAUSE -dBATCH -dSAFER -dJPEGQ=100 \
    -dFirstPage=${1} \
    -dLastPage=${2} \
    -sOutputFile=doc-%02d.jpg \
    ${3}
    }
    after adding this to bashrc the command to produce images is this
    Code:
    pdf-extract 2 5 *.pdf

    Sweet
    Ubuntu user number # 29587

    I'm Jet Black, 36 years old. I'm often told I don't look 36, but you shouldn't judge people based on appearances... or on how much hair they have.

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
  •