Getting error when converting pdf to jpeg

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

Post Reply
Mattias
Posts: 4
Joined: Mon Feb 25, 2019 7:56 am

Getting error when converting pdf to jpeg

Post by Mattias »

Hello

I've been using xnconvert for abit to convert pdfs to jpeg files and it's been working great but now i want to automate the process so i figured i'd have a go with nconvert but i'm not getting anywhere ..

I'm doing a simple convertion using

nconvert -o jpeg 1.pdf

but when it runs i get an error:
C:\test>nconvert -o jpeg 1.pdf
** NCONVERT v7.25 (c) 1991-2019 Pierre-E Gougelet (Jan 15 2019/12:05:55) **
Version for Windows Xp/Vista/7 x64 (All rights reserved)
** This is freeware software (for non-commercial use)

GS: (C:\Program Files\gs\gs9.26\bin\gsdll64.dll)
ARG 0 -dNODISPLAY
ARG 1 -dQUIET
ARG 2 -sPDFname=1.pdf
ARG 3 -sDSCname=C:\Users\matnil\AppData\Local\Temp\x_3EEC.tmp
ARG 4 pdf2dsc.ps
ARG 5 -c quit
ARG 6 -c quit
==> 112
ERROR: -101
GS: (C:\Program Files\gs\gs9.26\bin\gsdll64.dll)
ARG 0 -dBATCH
ARG 1 -dFirstPage=1
ARG 2 -dLastPage=1
ARG 3 -dMaxBitmap=300000000
ARG 4 -sDEVICE=tiff24nc
ARG 5 -q
ARG 6 -dNOPAUSE
ARG 7 -dSAFER
ARG 8 -dTextAlphaBits=4
ARG 9 -dGraphicsAlphaBits=4
ARG 10 -g839x593
ARG 11 -r72x72
ARG 12 -sOutputFile=C:\Users\matnil\AppData\Local\Temp\x_3F4A.tmp
ARG 13 1.pdf
ARG 14 -c quit
ARG 15 -c quit
==> 219
GS>Over...
Conversion of 1.pdf into jpeg.pdf OK
and it outputs a new file called jpeg.pdf instead of a jpeg file.

i use 64bit version of nconvert and ghostscript, any idea what i'm doing wrong here?
cday
XnThusiast
Posts: 3976
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Getting error when converting pdf to jpeg

Post by cday »

Please try:
nconvert -out jpeg -o filename.jpg 1.pdf

The -out and -o switches are easily confused, if the above code doesn't work I'll have a closer look later.

You may also wish to add a -q term to set the JPEG compression level, such as -q 80 .
Mattias
Posts: 4
Joined: Mon Feb 25, 2019 7:56 am

Re: Getting error when converting pdf to jpeg

Post by Mattias »

oh! Well that worked fine :)

i got confused because when i exported the bat file from xnconvert it told me to use -o for format

this is what i got from xnconvert:

nconvert -rotate 90 -ratio -rtype lanczos -resize 650 600 -o jpeg -q 80

so i edited it to this:

nconvert -rotate 90 -ratio -rtype lanczos -resize 650 600 -out jpeg -q 80 -o 1.jpg 1.pdf

and it works fine

Many thanks :)
cday
XnThusiast
Posts: 3976
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Getting error when converting pdf to jpeg

Post by cday »

Mattias wrote: Mon Feb 25, 2019 10:43 am i got confused because when i exported the bat file from xnconvert it told me to use -o for format

this is what i got from xnconvert:

nconvert -rotate 90 -ratio -rtype lanczos -resize 650 600 -o jpeg -q 80

I think you could usefully report that as a bug in the XnConvert section of the forum... :D
Mattias
Posts: 4
Joined: Mon Feb 25, 2019 7:56 am

Re: Getting error when converting pdf to jpeg

Post by Mattias »

on that note i got a followup question, in xnconvert i can check convert all pages from multipage file and i figured the option for nconvert might be -multi but that does not seem to produce more then one page even though my pdf is 3 pages.

i always want to extract the last page in my automated batch job and -page works but it does not always have x amount of pages so i would need it to always only get the last page (i tried -page last but that had no effect and took the first page instead) .. is there a command to get the last page of a pdf?
cday
XnThusiast
Posts: 3976
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Getting error when converting pdf to jpeg

Post by cday »

Mattias wrote: Mon Feb 25, 2019 11:02 am on that note i got a followup question, in xnconvert i can check convert all pages from multipage file and i figured the option for nconvert might be -multi but that does not seem to produce more then one page even though my pdf is 3 pages.

Code: Select all

-xall             : Extract all images
The option -multi is for the creation of multipage files, again confusing but defined in the NConvert help file.

i always want to extract the last page in my automated batch job and -page works but it does not always have x amount of pages so i would need it to always only get the last page (i tried -page last but that had no effect and took the first page instead) .. is there a command to get the last page of a pdf?
I'm not sure, could you try that again after making the above change to your code...
Mattias
Posts: 4
Joined: Mon Feb 25, 2019 7:56 am

Re: Getting error when converting pdf to jpeg

Post by Mattias »

thanks, xall extracts all pages with page name in the end of the name, i guess ill have to come up with some renaming algo to get the last page only .. best way would be if there was a way to check which page number is the last page then extract only that page but this will work for now :)
cday
XnThusiast
Posts: 3976
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Getting error when converting pdf to jpeg

Post by cday »

Mattias wrote: Mon Feb 25, 2019 12:59 pm thanks, xall extracts all pages with page name in the end of the name, i guess ill have to come up with some renaming algo to get the last page only .. best way would be if there was a way to check which page number is the last page then extract only that page but this will work for now :)

There are ways of counting the number of files in a folder, Google if that would help...

There is also:

Code: Select all

-o filename       : Output filename
              Use # to specify position of numeric enumerator
...but I imagine that only affects the base filename, so probably no help.

Edit:

If you hit a problem this untested method should work:

o Extract all pages to a folder;

o Set a variable equal to the number of files in the folder, using for example one of the methods described here ;

o Delete all of the files in the folder;

o Extract the last page using the above count variable as the page number.
Post Reply