LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I need help converting pdfs to jpegs. (https://www.linuxquestions.org/questions/linux-newbie-8/i-need-help-converting-pdfs-to-jpegs-4175578317/)

gleftwich 04-25-2016 07:26 PM

I need help converting pdfs to jpegs.
 
How can I convert a pdf to a jpeg on linux Rebecca?

frankbell 04-25-2016 07:33 PM

The easiest way is to open ("import") the PDF into the GIMP, then export it as a *.jpg or other desired format. If the GIMP is not already installed, it is in the Mint repos.

If PDF has multiple pages, you can use imagemagick: http://xmodulo.com/convert-pdf-files...-on-linux.html

Shadow_7 04-25-2016 08:05 PM

I tend to use a2ps for that. And then convert the .ps with gimp or convert (imagemagick). But mostly because I can extract individual pages and keep the correct landscape/portrait orientation with anything to postscript "a2ps". With the correct parameters. YMMV

TB0ne 04-26-2016 09:23 AM

Quote:

Originally Posted by gleftwich (Post 5536497)
How can I convert a pdf to a jpeg on linux Rebecca?

There are thousands of documents on Google about how to do this.

The "convert" command from Imagemagick can do it, and you can also play with the resolution/size of the images on output too.
The PDF toolkit (pdftk) may also work.

To convert a PDF to PNG with pretty good resolution:
Code:

convert -density 300 file.pdf file.png
To rotate a PDF:
Code:

pdftk nonrotated.pdf cat 1-endW output rotated.pdf
To size a PDF to a desired size (this example is A4):
Code:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=a4 -sOutputFile=output.pdf input.ps

ondoho 04-26-2016 01:49 PM

+1 for imagemagick if you want automation; for a one-off gimp is probably best.

Michael Uplawski 04-26-2016 02:35 PM

With Ghostscript, you convert many files to many different image-formats. For a long time, already, I use the following script for this kind of work. I do not recommend the script and just put it here to economize on bad English. Examples are in general easier to understand... ;-)
Check the available Ghostscript devices. I know that for the output of tiffs the script had to be adapted once, but it should normally be okay, like it is.

Code:

#!/bin/bash
#
# prints files to image
# ©2007-2016 Michael Upawski <michael.uplawski@uplawski.eu>
# License-agreement: Modify the file as pleases you; use at your own risk as it
# may do some harm somewhere or not (lay your home in ashes, make you crow's
# feet and what not.., buys you a Volvo, you know that kind of stuff.)
# I forbid use of this script to any European governmental agencies as well as
# to each one of their paying customers.

# defaults
TYPE=tif
DEV=tiff24nc
RES=400x400
PAPER=a4
GS=/usr/bin/gs
SCRIPT=`basename "$0"`

USAGE="Syntax:\n\tuser@machine:$PWD\$ $SCRIPT [file0] <file1> ... <filen>\nWill create 1 file converted to $TYPE for each page in any of the input-files.\
\n\tusr@machine:$PWD/\$ $SCRIPT <output type> [file0] <file1> ... <filen>\nWill instead create files of the specified output type e.g. jpeg, png, pgm"

if [ "$#" -gt 0 ]
then
        case "$1" in
                tif)
                        TYPE=tif
                        DEV=tiffscaled24
                        shift 1
                ;;
                tiff)
                        TYPE=tiff
                        DEV=tiffscaled24
                        shift 1
                ;;
                jpg)
                        TYPE=jpg
                        DEV=jpeg
                        shift 1
                ;;
                jpeg)
                        TYPE=jpeg
                        DEV=jpeg
                        shift 1
                ;;
                pgm)
                        TYPE=pgm
                        DEV=pgm
                        shift 1
                ;;
                png)
                        TYPE=png
                        DEV=png48
                        shift 1
                ;;
                pcx)
                        TYPE=pcx
                        DEV=pcx24b
                        shift 1
                ;;
                bmp)
                        TYPE=bmp
                        DEV=bmp256
                        shift 1
                ;;
        esac

        if [ "$#" -gt 0 ]
        then
                for inf in "$@"
                do
                        ext=${inf}       
                        DIR=`dirname "$inf"`
                        if [ "$DIR"=='' ]
                        then
                                DIR='.'
                        fi
                        OUTPUT="$DIR"/`basename "$inf" ."$ext"`_%04d."$TYPE"
                        echo "creating files $OUTPUT"       
                        # /usr/bin/gs -SDEVICE="$DEV" -r"$RES" -sPAPERSIZE="$PAPER" -sOutputFile="$OUTPUT" -dNOPAUSE -dBATCH -- "$inf"
                        "$GS" -SDEVICE="$DEV" -r"$RES" -sPAPERSIZE="$PAPER" -sOutputFile="$OUTPUT" -dNOPAUSE -- "$inf"
                done
        else
                echo -e "ERROR: No files"
                echo -e "$USAGE"
        fi
else
        echo -e "ERROR: No arguments."
        echo -e "$USAGE"
fi

Edit: I am a bit dumb, as I forgot that I even have a blog-entry on that subject..: Crete images from PDF and recreate PDF from images

Fred Caro 04-26-2016 07:55 PM

easy method, open a terminal and do:

Quote:

convert some.pdf some.jpg
in the relevant directory.

Fred.

Michael Uplawski 04-27-2016 07:28 AM

With convert, which quality setting do you use to ensure a decent conversion of text? -quality 100 is not enough, in my opinion.

TB0ne 04-27-2016 08:02 AM

Quote:

Originally Posted by Michael Uplawski (Post 5537257)
With convert, which quality setting do you use to ensure a decent conversion of text? -quality 100 is not enough, in my opinion.

See my post above. I get pretty good results with -density=300, but that's just for my use. Your mileage may vary.

Michael Uplawski 04-27-2016 12:13 PM

Quote:

Originally Posted by TB0ne (Post 5537277)
See my post above. I get pretty good results with -density=300, but that's just for my use. Your mileage may vary.

:hattip: Thank you very much. I had misinterpreted the density option until now. Very fine!


All times are GMT -5. The time now is 03:05 PM.