Read PDF from BLOB and Export it as PNG BLOB.

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Dilshod

Read PDF from BLOB and Export it as PNG BLOB.

Post by Dilshod » 2005-07-06T19:45:18-07:00

Hello everyone,

I am having some issues reading PDF from BLOB and exporting in another format. My code uses ImageWand to manipulate the images. It works perfectly for image types with native blob support however for PDF format ImageMagic generates temp files (and lots [over 1000] of them as /tmp/magick-XX******). Then it crashes after a few seconds. The temp files have either 0 bytes or 1 byte.

According to manual pages, the ImageMagick can have a native blob support for PDF formats. So, how can I configure the ImageMagic to use native blob instead of writing to disk?

Thank you,

Dilshod.

User avatar
magick
Site Admin
Posts: 11015
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2005-07-07T13:47:19-07:00

ImageMagick has regressions tests which suggest blob support for PDF works. Can you post a code snippet we can try and reproduce the problem. It appears the PDF coders is being called repeatedly.

Dilshod

Post by Dilshod » 2005-07-08T12:35:25-07:00

thank you. I am preparing the snippet. I need clean up the code before I can post it publically.
magick wrote: ImageMagick has regressions tests which suggest blob support for PDF works. Can you post a code snippet we can try and reproduce the problem. It appears the PDF coders is being called repeatedly.

Dilshod

Post by Dilshod » 2005-07-09T15:25:21-07:00

Here is the code that's giving me the trouble:

thanks again for you help!

if you need more clarification please ask

Code: Select all

void convert(  ... )
{
  sword     err;

  unsigned long        i;

  unsigned long offset = 1;
  unsigned long blob_in_length;
  unsigned long local_buflen;
  unsigned long *local_buf;		


  unsigned char	*local_buf_magic_out;
  size_t local_buf_magic_out_len;
  unsigned long 	 page_cnt;

  MagickBooleanType  status;
  MagickWand  *magick_wand;

  ...
  
    magick_wand=NewMagickWand();  

    /* Read an image from local_buf into magick_wand */    
    status=MagickReadImageBlob(magick_wand,(void *)local_buf, (size_t) ( local_buflen));

    page_cnt = MagickGetNumberImages(magick_wand);

MagickResetIterator(magick_wand);
   
for (i=0; i < page_cnt; i++) { 

   status=MagickNextImage(magick_wand) ;

   status=MagickSetImageFormat(magick_wand,"PNG");

   local_buf_magic_out = MagickGetImageBlob(magick_wand, &local_buf_magic_out_len);   
      

/*   export LOB */
   err = lobWrite(...
                    lobp[i], 
                    local_buf_magic_out_len, 
                    ...
                    local_buf_magic_out, 
                    local_buf_magic_out_len, 
		    ...); 
 
   local_buf_magic_out = MagickRelinquishMemory(local_buf_magic_out);

}

   magick_wand=DestroyMagickWand(magick_wand);


}

Dilshod

Post by Dilshod » 2005-07-20T19:08:41-07:00

Yes the initial BLOB comes from Oracle, but I read it to a local buffer first.

The interesting thing is that it works fine other image types that support native blob.

Is anyone able to give me a direction or suggestion?

thanks again.
blueronin wrote: Dilshod, are you reading the blob from Oracle?

Dilshod

Post by Dilshod » 2006-07-20T16:46:26-07:00

e12win wrote: Is there a solution yet for this problem? I am running into the same problem where I am using MagickReadImageBlob to read a blob/binary from pdf files and the program basically just sits there doing nothing. I notice that it created some files in /tmp/.

Any help??

Thanks,
Erwin



No, I am still looking for a solution to the problem. The recent workaround was that I used Java to write a file out and then execute convert command, and bring the files back into database. While I was developing this workaround, I came across one issue about not having eviroment path to "gs" (ghostscript) file. So I had to modify imagemagick's config to specify the full path to gs. (imagemagic uses gs app to convert from PDF to PNG, and it uses in command line fashion).

The config file is located: /usr/local/lib/ImageMagick-6.2.8/config/delegates.xml

My mods looked something like this:

Code: Select all

<delegate decode="ps:color" stealth="True" command='"/usr/local/bin/gs" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=pnmraw" -dT
extAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />
where it used to be:

Code: Select all

<delegate decode="ps:color" stealth="True" command='"gs" -q -dBATCH -dSAFER -dMaxBitmap=500000000 -dNOPAUSE -dAlignToPixels=0 -dEPSCrop "-sDEVICE=pnmraw" -dT
extAlphaBits=%u -dGraphicsAlphaBits=%u "-g%s" "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"' />

Post Reply