【问题标题】:tcpdf $pdf->Output('out.pdf', 'I'); gone badtcpdf $pdf->输出('out.pdf', 'I');变坏了
【发布时间】:2023-03-02 21:59:01
【问题描述】:

我正在尝试学习 TCPDF,但遇到了一个奇怪的问题,这是我的代码被示例提取的。

require_once('../tcpdf.php');
ob_start();

// create new PDF document
$pdf = new TCPDF("P","mm","A4",true,"UTF-8",false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('User');
$pdf->SetTitle('TCPDF');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));

// 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->SetHeaderMargin(PDF_MARGIN_HEADER);
$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 (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

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

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
//~ $pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

$html = "ASD";
$pdf->writeHTML($html, true, false, true, false, '');   
ob_end_clean();
$pdf->Output('prova.pdf', 'I');`

当 PHP 到达输出命令时出现问题,它不会在浏览器上打开 PDF 页面,而是打印一个奇怪的输出,就像使用文本编辑器打开 PDF 文件一样。 这里我用的是writeHTML(),但是和Image()一样,我已经试过了。

我哪里做错了?

【问题讨论】:

    标签: tcpdf


    【解决方案1】:

    我测试了你所做的事情,我为我工作,我想再次下载 tcpdf API 并将其替换为你当前的文件夹。 还有关于图片:确保你的图片类型是.jpg as

      $html = "ASD
    <img src="project path/images/image.jpg"/>
    ";
    

    【讨论】:

      【解决方案2】:

      您需要一个 Content-Disposition 标头。

      查看其他帖子:PHP Content-Disposition: attachment / Content-Type

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-19
        • 1970-01-01
        • 2013-01-10
        • 2013-05-13
        • 2020-08-25
        • 2011-05-28
        相关资源
        最近更新 更多