Image Magick converts only the first 4 pages of an pdf 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
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

Hi,

i want to use image magick to convert pdf files into images, one image for each page. i tried this command:

Code: Select all

convert -density 600x600 -units pixelsperinch aaa.pdf -background white -alpha background -alpha off -scene 1 -resize 50% -compress jpeg +adjoin "neuer"_%02d.tif
but it only converts the first four pages of the pdf into images. i created this command line on ubuntu 16.04 with the last version in the repositories. the ubuntu doesn't exist so i can't check the version. now i'm on ubuntu 18.04 with imagemagick 6.9.7-4.

what is wrong woth the command line?

edit
i tried it with an other pdf file with a lower resolution, here it converts the first five pages and there is an error:

Code: Select all

convert-im6.q16: DistributedPixelCache '127.0.0.1' @ error/distribute-cache.c/ConnectPixelCacheServer/244.
convert-im6.q16: cache resources exhausted `/tmp/magick-6892fkK6Ueon7ldI6' @ error/cache.c/OpenPixelCache/3984.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

Flokker wrote:cache resources exhausted `/tmp/magick-6892fkK6Ueon7ldI6'
You don't have enough available memory for the operation, so IM is trying to use disk (/tmp), but that doesn't have enough space either.
snibgo's IM pages: im.snibgo.com
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

but there is enough memory free. i have a conky running on my desktop that shows me the free and used memery and the used was max. 1.5gb. i have 16gb.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

IM is trying to write to /tmp, and failing. How much free space there?

EDIT: And you might have resource limits. What does "convert -list resource" say?
snibgo's IM pages: im.snibgo.com
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

Code: Select all

Resource limits:
  Width: 16KP
  Height: 16KP
  Area: 128MP
  Memory: 256MiB
  Map: 512MiB
  Disk: 1GiB
  File: 768
  Thread: 12
  Throttle: 0
  Time: unlimited
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

So your computer has 16 GB memory, but IM is allowed to use only 0.25 GB. So that will fail, and IM will use disk, but is allowed only 1 GB. (I'm ignoring the small difference between GB and GiB.)

I suggest you edit your policy.xml file to allow more resources to be used for Area, Memory, Map and Disk.
snibgo's IM pages: im.snibgo.com
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

but why do i have so littel values in that file? on ubuntu i had this values (the system had 8gb ram):

Code: Select all

  <!-- <policy domain="resource" name="memory" value="2GiB"/> -->
  <!-- <policy domain="resource" name="map" value="4GiB"/> -->
  <!-- <policy domain="resource" name="area" value="1GB"/> -->
  <!-- <policy domain="resource" name="disk" value="16EB"/> -->
  <!-- <policy domain="resource" name="file" value="768"/> -->
  <!-- <policy domain="resource" name="thread" value="4"/> -->
  <!-- <policy domain="resource" name="throttle" value="0"/> -->
  <!-- <policy domain="resource" name="time" value="3600"/> -->
  <!-- <policy domain="system" name="precision" value="6"/> -->
i'm wondering about the "16EB" fpr disk.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

Flokker wrote:on ubuntu i had this values
All those lines are comments. "<!-- ... -->" in XML is a comment.

An exabyte is a thousand terrabytes. Or a million, I forget.
snibgo's IM pages: im.snibgo.com
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

yes, you're right. so on ubuntu there was no settings like this because there is nothing more in the xml.

i guess image magick first loads all pagesof the pdf to the ram and then converts into images? wouldn't it be better when it loads each page to the ram, then convert, load the next then convert and so on?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

ImageMagick first passes the entire PDF to Ghostscript, which rasterizes all the pages and passes these back to ImageMagick. The PDF might contain page numbers and so on, so that may need to be a single operation.

IM takes all those images, one per page, and performs your operations (eg "-resize 50%") on each one, then saves all the images as tiff files with JPEG compression, as requested.

IM can process groups of pages, if you tell it to by using numbers in square brackets, for example:

Code: Select all

convert aaa.pdf[5-10] x_%03d.tiff
This reduces the resources needed by IM. You can do one page at a time if want.

IM's resource limits don't apply to delegates, so Ghostscript can use as much memory and disk as it wants.
snibgo's IM pages: im.snibgo.com
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

snibgo wrote: 2018-07-15T07:31:32-07:00This reduces the resources needed by IM. You can do one page at a time if want.
ok, but this converts only the page 5 to 10. i want the whole pdf. the question is: can i speed up the whole process of converting all pages of a pdf to tif when i run a separate process for each site instead of one process for of pages of the document? if so, can i set up so that IM converts every site in an extra process? if not i have to create a command for every page manually.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Image Magick converts only the first 4 pages of an pdf file

Post by snibgo »

If all the pages will fit in your memory, the fastest way is in a single "convert" or "magick" command.

But if you want to use the least memory, then run one convert command per page, using aaa.pdf[0], aaa.pdf[1] etc. You can do this in a shell "for" loop.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Magick converts only the first 4 pages of an pdf file

Post by fmw42 »

Flokker wrote: 2018-07-15T03:47:06-07:00

Code: Select all

Resource limits:
  Width: 16KP
  Height: 16KP
  Area: 128MP
  Memory: 256MiB
  Map: 512MiB
  Disk: 1GiB
  File: 768
  Thread: 12
  Throttle: 0
  Time: unlimited
Who set these limits? Can you not edit your policy.xml file to give you more resources? Is this your own computer or on a shared host. If it is your computer, then you should be able to increase your Memory usage. If it is on a shared server, then they have set the max limits and you can only decrease them.
Flokker
Posts: 17
Joined: 2018-07-15T00:32:10-07:00
Authentication code: 1152

Re: Image Magick converts only the first 4 pages of an pdf file

Post by Flokker »

its my own computer.

nobody set this limits. i never changed this file. this are the settings after installing imagemagic.

what are god settings for my system? i have installed 16GiB RAM.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image Magick converts only the first 4 pages of an pdf file

Post by fmw42 »

Edit your policy.xml file. See the locations at http://www.imagemagick.org/script/resources.php. On my Mac, it is located at

Code: Select all

find /usr | grep "policy.xml"
/usr/local/etc/ImageMagick-6/policy.xml

On my Mac with 8GB RAM, my default resource settings are:

Code: Select all

convert -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  List length: 18.446744EP
  Area: 17.18GP
  Memory: 8GiB
  Map: 16GiB
  Disk: unlimited
  File: 192
  Thread: 4
  Throttle: 0
  Time: unlimited
So my Memory is the same as the amount of RAM that I have and the Map is 2x that, though I am not sure why.
Post Reply