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);