PDF to PNG

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
Sisel

PDF to PNG

Post by Sisel »

Hello,

im little noob in this so maybe it will have simple solution :)

i have installed ImageMagick 6.4.8 on some provider and wanna use it for converting pdf to png for my ebook, so i need to convert it to 3 formats - 1024(for zoomed images) 400(for ebook preview) and 120(for thumbnails). My problem is that my pdfs is differents and i need to have all them with redeable letters.

I have severals problems with it...
if i dont use -density i dont get images where i can easily read the text, but without that parameter i didnt notice any error in any pdf i converted.
if i dont use -depth 8 i got images at 48bits, which is too big - about 6MB per file and if i use it i got 24bit images with 1Mb size, which is ok, but im unable to convert everything fine ;(

when i try to convert few examples pdf with this script...

Code: Select all

<?php
ini_set('max_input_time', 0);
ini_set('max_execution_time', 0);
ini_set('memory_limit', '256M');
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '20M');

exec("convert -density 200 $pdf_file1 -quality 90 -resize 1024 -depth 8 page1.png 2>error1.log");
exec("convert -density 200 $pdf_file2 -quality 90 -resize 1024 -depth 8 page2.png 2>error2.log");
exec("convert -density 200 $pdf_file3 -quality 90 -resize 1024 -depth 8 page3.png 2>error3.log");
exec("convert -density 200 $pdf_file4 -quality 90 -resize 1024 -depth 8 page4.png 2>error4.log");
exec("convert -density 200 $pdf_file5 -quality 90 -resize 1024 -depth 8 page5.png 2>error5.log");
exec("convert -density 200 $pdf_file6 -quality 90 -resize 1024 -depth 8 page6.png 2>error6.log");
?>
im getting errors for 4 pdfs...

Code: Select all

error1.log - convert: missing an image filename `page1.png' @ convert.c/ConvertImageCommand/2756.
error3.log - ESP Ghostscript 815.02: Unrecoverable error, exit code 1
error3.log - convert: Postscript delegate failed `/home/citywayc/public_html/test/3.pdf': No such file or directory @ pdf.c/ReadPDFImage/612.
error3.log - convert: missing an image filename `page3.png' @ convert.c/ConvertImageCommand/2756.
error4.log - convert: Memory allocation failed `Cannot allocate memory' @ exception.c/AcquireExceptionInfo/108.
error5.log - ESP Ghostscript 815.02: Unrecoverable error, exit code 1
error5.log - convert: Postscript delegate failed `/home/citywayc/public_html/test/5.pdf': No such file or directory @ pdf.c/ReadPDFImage/612.
error5.log - convert: missing an image filename `page5.png' @ convert.c/ConvertImageCommand/2756.

new error in everything...
convert: `%s': %s "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r200x200"  "-sOutputFile=/tmp/magick-XXV3T2G5" "-f/tmp/magick-XXqXQWQD" "-f/tmp/magick-XXBrLX0b" @ utility.c/SystemCommand/1834.
All testing files is located at
http://www.cityway.com/test/1.pdf
http://www.cityway.com/test/2.pdf
http://www.cityway.com/test/3.pdf
http://www.cityway.com/test/4.pdf
http://www.cityway.com/test/5.pdf
http://www.cityway.com/test/6.pdf

So could you please someone help me, what im doing wrong? I dont mutch care in which format i will have that images i just need to have nice text with them which i can nicely read :)

Oh i forgot to add just in case the configuration

Code: Select all

    [0] => 
    [1] => Path: /usr/lib64/ImageMagick-6.4.8/config/configure.xml
    [2] => 
    [3] => Name          Value
    [4] => -------------------------------------------------------------------------------
    [5] => CC            gcc -std=gnu99
    [6] => CFLAGS        -fopenmp -g -O2 -Wall -W -pthread
    [7] => CONFIGURE     ./configure  '--prefix=/usr' '--libdir=/usr/lib64'
    [8] => COPYRIGHT     Copyright (C) 1999-2009 ImageMagick Studio LLC
    [9] => CPPFLAGS      -I/usr/include/ImageMagick
    [10] => CXX           g++
    [11] => CXXFLAGS      -g -O2 -Wall -W -pthread
    [12] => DEFS          -DHAVE_CONFIG_H
    [13] => DELEGATES     bzlib fontconfig freetype gs jpeg png rsvg tiff x11 xml wmf zlib
    [14] => DISTCHECK_CONFIG_FLAGS --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-fontpath=
    [15] => EXEC-PREFIX   /usr
    [16] => HOST          x86_64-unknown-linux-gnu
    [17] => LDFLAGS       -L/usr/lib64 -lfreetype
    [18] => LIB_VERSION   0x648
    [19] => LIB_VERSION_NUMBER 6,4,8,2
    [20] => LIBS          -lMagickCore -ltiff -lfreetype -ljpeg -lfontconfig -lXext -lSM -lICE -lX11 -lbz2 -lz -lm -lgomp -lpthread
    [21] => NAME          ImageMagick
    [22] => PCFLAGS       -fopenmp
    [23] => PREFIX        /usr
    [24] => QuantumDepth  16
    [25] => RELEASE_DATE  2010-09-21
    [26] => VERSION       6.4.8
    [27] => WEBSITE       http://www.imagemagick.org
Last edited by Sisel on 2010-11-06T08:08:44-07:00, edited 2 times in total.
Sisel

Re: PDF to PNG

Post by Sisel »

I also have working version in ImagicK, which i cants use in this server, but that have other problem, that is too slow when i try to convert 2MB+ pdf with 10+ pages.
16MB and 58 pages it took the server about 2 hours. So if someone can give me also hint there if there is something how i can speed it up

Code: Select all

  $images = new Imagick();
  $images->setResolution( 300, 300 );
  $images->readImage($pdf_file);
  $i = 0;
  set_time_limit(0);

  foreach ($images as $k => $image) {
      /******************************
      * CREATE LARGE IMAGE
      ****************************/

      $image->setImageFormat("gif");
      $image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
      $image->setImageResolution(72, 72);

      // Write out large image, for ebbok.
      $large_image = $jpg_loc."page-".$k.".gif";
      $image->thumbnailImage(1024, NULL);
      $image->writeImage($large_image);
   }

  foreach ($images as $k => $image) {
      /******************************
      * CREATE SMALL IMAGE
      ****************************/

      $image->setImageFormat("gif");
      $image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
      $image->setImageResolution(72, 72);

      // Write out small image, for ebbok.
      $small_image = $jpg_loc."page_mini-".$k.".gif";
      $image->thumbnailImage(400, NULL);
      $image->writeImage($small_image);
  	  ++$i;
  }

  foreach ($images as $k => $image) {
		/******************************
		 * CREATE THUMB IMAGE
		 ****************************/

		$image->setImageFormat("gif");
		$image->setImageUnits(Imagick::RESOLUTION_PIXELSPERINCH);
		$image->setImageResolution(72, 72);

		// Write out small image, for ebbok.
		$thumb_image = $jpg_loc."page_thumb-".$k.".gif";
		$image->thumbnailImage(120, NULL);
		$image->writeImage($thumb_image);
	}

  $image->clear();
  $image->destroy();
Sisel

Re: PDF to PNG

Post by Sisel »

heh, no one can give a hints what i can do? :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDF to PNG

Post by fmw42 »

Post Reply