0

我将 pdf 保存在服务器中(生成的 py TCPDF),我需要预览它们。我的预览代码适用于某些 pdf,但不适用于其他 pdf。

我的代码:

$filehandle = fopen( $urlPdf, "rb");
$img = new Imagick();
$img->readimagefile($filehandle);

代码继续,但问题出现在上述行之后,因为当我将 die() 放在它们之后时,我遇到了同样的错误:

Postscript delegate failed `/tmp/magick-XXtHvIKA': No such file or directory

这是我生成pdf的方式:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('CSI');
$pdf->SetTitle('Pismo');
$pdf->SetSubject('Pismo');
$pdf->SetKeywords('CSI');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// add a page
$pdf->AddPage();
$pdf->SetFont('dejavusans', '', 10);

// create some HTML content
if ($image->kind == 0){
$html ='<img src="../public/img/ci2.png"/ style="width: 620px"/><br>';
}
else {
    $html ='<img src="../public/img/kan.png"/ style="width: 620px"/><br>';
}
$pdf->writeHTML($html, true, 0, true, true);
$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="0">
<tr>
    <td><img src="../barcodes/$image->id.png" style="width: 200px;position:absolute;left:550px;top:50px;"/></td>
    <td>$line</td>
</tr>
<tr>
<td></td>
<td  style="text-align:right;">Warszawa, $image->date</td>
</tr>
</table>
EOD;

$pdf->writeHTML($tbl, true, false, true, false, '');

$html = '<br>'.stripslashes($image->content);

// output the HTML content
$pdf->writeHTML($html, true, 0, true, true);

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdfPreviewUrl = Doctrine::getTable('Configurations')->find('pdfPreviewUrl');
$pdf->Output($pdfPreviewUrl->value.$image->id.'.pdf', 'F');
4

0 回答 0