pdf to jpg with big file

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stephane44
Posts: 5
Joined: 2018-11-17T02:16:24-07:00
Authentication code: 1152

pdf to jpg with big file

Post by stephane44 » 2018-11-17T02:54:46-07:00

Hello,

I am happy to have found this forum because I can not run my script.

My version of convert ( my code is running under debian 9 ) :

Code: Select all

# convert -version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
I run my code under php, I put a longer execution time to avoid any problem, especially for large files.

I explain my problem. I need to turn a pdf into a jpg image. My pdf has many pages (250 pages) but after the transformation, I find only 75 pages.

Code: Select all

$output = exec('convert -density 150 -trim -limit thread 1 "./pdf/1.pdf" -quality 50 "./livres/0001/'.$file.'/1.jpg"' );
echo $output;
I would like if it is possible to have an opinion. I want to turn my 1.pdf file into 1-wide.jpg, 2-wide.jpg etc ...

And then convert those smaller 1.jpg files and a smaller file for a thumbnail 1-thumb.jpg.

I would also like to know if we can limit the script to prevent it blocking the server.

I use -limit thread, is it useful.

Thank you in advance for your answer.

Even if I do not have all the answers, it will still be very good.

Stéphane

snibgo
Posts: 12024
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to jpg with big file

Post by snibgo » 2018-11-17T03:26:15-07:00

stephane44 wrote:My pdf has many pages (250 pages) but after the transformation, I find only 75 pages.
Did you get an error message? Perhaps you ran out of memory. How many pixels are in each page?

It may be better to convert your PDF in sections, eg "./pdf/1.pdf[0-9]" then "./pdf/1.pdf[10-19]" etc.
stephane44 wrote:I want to turn my 1.pdf file into 1-wide.jpg, 2-wide.jpg etc ...
Sorry, I don't understand.
I would also like to know if we can limit the script to prevent it blocking the server.
Yes. You can set limits system wide or just for particular users in policy.xml. Or use "-limit" in individual commands.

"-limit" is documented at http://www.imagemagick.org/script/comma ... .php#limit

See also http://www.imagemagick.org/script/resources.php
snibgo's IM pages: im.snibgo.com

stephane44
Posts: 5
Joined: 2018-11-17T02:16:24-07:00
Authentication code: 1152

Re: pdf to jpg with big file

Post by stephane44 » 2018-11-17T03:56:10-07:00

Ok to extract a little bit, you're right it's smarter than what I did. Do you have a track to know if my function has transformed something without going to count the .jpg.

I want to transform my 1.pdf into 1-large.jpg in one go, without having to rename my .jpg. Is it possible?

I want to transform my 1.pdf file into 1-wide.jpg, 2-wide.jpg with convert. I would like to keep the proportions. How can I do?

Thank you for your answers, I have already made good progress.

Stéphane

snibgo
Posts: 12024
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to jpg with big file

Post by snibgo » 2018-11-17T04:01:50-07:00

stephane44 wrote:I want to turn my 1.pdf into 1-large.jpg in one go, without having to rename my .jpg. Is it possible?
You can rasterize the PDF into images, one image per page. Then append those images vertically. Is that what you mean?

Code: Select all

convert input.pdf -append out.jpg
Or "+append" will append them horizontally.

Your OP command included "-trim". That should come after reading the PDF, not before it.
snibgo's IM pages: im.snibgo.com

stephane44
Posts: 5
Joined: 2018-11-17T02:16:24-07:00
Authentication code: 1152

Re: pdf to jpg with big file

Post by stephane44 » 2018-11-17T04:13:10-07:00

My code:

Code: Select all

convert -density 150 "/var/www/nemotechnology/pdf/1.pdf[0]" -quality 50 -trim "/var/www/nemotechnology/livres/0001/1.jpg"
What does trim do you do?
I would like to have the transformation and renaming of images at once like that.

Code: Select all

convert -density 150 "/var/www/nemotechnology/pdf/1.pdf[0]" -quality 50 -trim "/var/www/nemotechnology/livres/0001/1-large.jpg"
What is the difference between quality and density please?
I'm boring but I really need to understand what I'm doing.
Stéphane

snibgo
Posts: 12024
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to jpg with big file

Post by snibgo » 2018-11-17T04:35:26-07:00

"-density" is a setting that affects the rasterisation of vector elements in the PDF, the process that changes lines or text into pixels. The unit is pixels per inch. If you double the number, you get twice as many pixels in width and in height.

"-trim" crops the image so that no edge has a single colour. For example, if you image is some text on a white background with a white border, it will remove the border.

"-quality" is a setting for writing JPG files. It is a number between 0 and 100. Lower numbers give smaller files but worse quality.

See:
http://www.imagemagick.org/script/comma ... ptions.php for the options
http://www.imagemagick.org/Usage/basics/ for basic usage.
snibgo's IM pages: im.snibgo.com

stephane44
Posts: 5
Joined: 2018-11-17T02:16:24-07:00
Authentication code: 1152

Re: pdf to jpg with big file

Post by stephane44 » 2018-11-17T04:46:12-07:00

Thank you for your answers. I think I'll be able to cope.

One last question, how do I know the page number of my pdf?

How to put resolute on this post?

snibgo
Posts: 12024
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: pdf to jpg with big file

Post by snibgo » 2018-11-17T05:19:36-07:00

I use exiftool for that, eg:

Code: Select all

f:\web\im>exiftool -args -PageCount mypdf.pdf

-PageCount=12
snibgo's IM pages: im.snibgo.com

stephane44
Posts: 5
Joined: 2018-11-17T02:16:24-07:00
Authentication code: 1152

Re: pdf to jpg with big file

Post by stephane44 » 2018-11-17T05:28:07-07:00

OK thanks to you
You made me a lot of time.

Good continuation
Stéphane

Post Reply