使用TCPDF库生成的PDF在Adobe Acrobat Reader中无法打印,但可以在预览中使用

问题描述

我正在使用TCPDF库版本:6.3.2(https://tcpdf.org/about/

pdf看起来不错,并且可以按预期导出。

当我使用“预览”查看并打印文件时,它工作正常。

但是,当使用Adobde Acrobat Reade时,我仍然可以查看文件,但无法打印它们。尝试打印时显示以下错误

'The document Could not be printed' -> first pop up error
'There were no pages selected to print' -> followed by the first error

enter image description here

enter image description here

我还使用$pdf->ImageSVG来绘制图表(https://www.goat1000.com/svggraph.php

我尝试过的事情:

  1. 在脚本启动之前添加ob_start(); ,并在ob_end_clean();之前添加$pdf->Output('thepdf.pdf','I');
    // $this->Image($image_file,10,15,'','PNG');
    // $this->Image($image_file,5,70,25,'PNG','T',true,300,false,false);

    $this->Image('@'.file_get_contents('pdf-logonew.jpg'),6,60,20);
    
    

    $html = '<h1 style="color:#d40b30; font-size:20px;">'.POST_NAME.'</h1>';
    

    $html_date = '<p style="margin-top:-10px;color:#3E3E3E;font-weight:bold;font-size:16px;">'.PDF_DATE.'</p>';

             
    $this->writeHTMLCell(
        $w=0,$h=0,$x=0,$y=15,$html,$border=0,$ln=0,$fill=false,$reseth=true,$align='R'
    );

    $this->writeHTMLCell(
        $w=0,$y=23,$html_date,$align='R'
    );

    // $pdf->SetTextColor(255,255,255);
    // $this->SetTextColor(255,0);
}

    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-20);
        // Set font
        $this->SetFont('helvetica','I',8);
        // Page number
        // $this->Cell(0,'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(),'C','M');
        // $this->Cell(0,'R','M');
    
        if ($this->page == 1){
        $footertext = '<hr style="color:#BDBDBD;background-color:transparent;"><p style="text-align:right;background-color:white;">Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages().'</p>';
        $this->writeHTML($footertext,true);

        }else{
            $footertext = '<hr style="color:#BDBDBD;background-color:transparent;"><p style="text-align:right;background-color:#e1e8ec;">Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages().'</p>';
        $this->writeHTML($footertext,true);
        }

    }
}
define ('PDF_MARGIN_TOP',200);

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

// convert TTF font to TCPDF format and store it on the fonts folder
// $fontname = TCPDF_FONTS::addTTFfont('Metropolis-Regular.ttf','TrueTypeUnicode',96);

// use the font
// $pdf->SetFont('metropolisfont',14,false);
// set document information
// $pdf->SetFont('times',44);
$pdf->SetFont('metropolisfont',44);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle(POST_NAME);
$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),128));
// $pdf->SetHeaderData('pdf-logo.png','70',$post_title,128));
// $pdf->setFooterData(array(0,0),128));
$pdf->setFooterData(array(0,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->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetHeaderMargin('100');
$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',true);


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


$description_html = '<div class="container" style="background-color:#FFFFFF;border: 0.25pt solid CutContour;border-radius: 10px 10px 10px 10px;"><p style="font-weight:bold;font-size:12px;line-height:16px;color:#3E3E3E;text-align:left;margin-bottom:0px;">Strategy Description - '.POST_NAME.'</p><p style="font-size:10px;text-align:left;line-height:13px;color:#404040;">'.STRATEGY_DESCRIPTION.'<p></div>';

$pdf->writeHTMLCell(0,80,23,$description_html,1,true);

$pdf->ImageSVG('@' . $graph_output,$x=80,$y=105,$w=$graph_width,$h=$graph_height,$link='#',$align='',$palign='',$fitonpage=true);

$pdf_name = POST_NAME." ".PDF_DATE;


$pdf_name =  str_replace(' - ',' ',$pdf_name);
// $pdf->Output($pdf_name.'.pdf','I');
// $pdf->Output('newnewsample'.'.pdf','I');
// $pdf->Output($new_custom_pdf_name.'.pdf','I');

ob_end_clean(); 
$pdf->Output($pdf_name.'.pdf','I');
exit();

这是一个更新 因此,我已找到导致问题$pdf->ImageSVG()的原因,似乎可以解决此问题。删除文件后,我可以在acrobat Reader中打印PDF,现在我调查ImgSVG()并了解如何我可以使它工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)