can't read PDF from BLOB and display /export it as PNG image

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Locked
osde8info

can't read PDF from BLOB and display /export it as PNG image

Post by osde8info »

same as 2 year old viewtopic.php?f=2&t=4494

Code: Select all

class mypdf {
	
	function proc($in,$out) {
 		
		$p = new PDFLib;
		
		$p->begin_document($out,'');

			$doc = $p->open_pdi_document($in,'');
			
			$pages = $p->pcos_get_number($doc, "length:pages");
	
			$w = $p->pcos_get_number($doc, "pages[0]/width");
	
			$h = $p->pcos_get_number($doc, "pages[0]/height");
			
			$pickapage = rand(1,$pages);
				
			$pag = $p->open_pdi_page($doc, $pickapage, '');
		
		$p->begin_page_ext(20,20,'');
		
		$p->fit_pdi_page($pag,0,0,'adjustpage');
	
		$p->end_page_ext('');
	
			$p->close_pdi_page($pag);
	
			$p->close_pdi_document($doc);
		
		$p->end_document('');
 
    return $p->get_buffer();
	}

}

$in = $_REQUEST['file'];

$out = tempnam('/tmp','pdf') ; 

$ext='PNG' ;

$mp = new mypdf;

$blob = $mp->proc($in,$out);

$w = NewMagickWand();   
   
MagickSetResolution($w, 200, 200);
MagickSetImageFormat($w, 'PDF');

// BROKEN
MagickReadImageBlob($w, $blob);

// WORKAROUND
// MagickReadImage($w, $out);

MagickSetImageFormat($w,$ext); 
header( 'Content-Type: image/' . $ext );
MagickEchoImageBlob( $w );

unlink($out);

Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: can't read PDF from BLOB and display /export it as PNG image

Post by Xandros »

magick ?

any chance to get a solution for this PDF BLOB issue please ? I posted a question in "Developers" explaining what I was doing, and apparently this issue has already 2 past unanswered threads with the same problem :(

Please give us a hand :)

Kind regards

Locked