WKHTMLtoPDF头文件内容未以PDF格式显示

mtp*_*ltz 7 php wkhtmltopdf

我试图使用我在这里找到的这个例子在第一页上隐藏页眉页码.只有当我使用footer-html并且如果我将它与header-html一起使用时,它才会显示/隐藏任何内容.最初我试图增加这个解决方案这也使用footer-html工作,但由于我不能让它在标题中工作,我继续搜索.我已经尝试了有没有'header-center'=>'[[page]]',以防万一使用header-html导致冲突.最近有人能够在标题中使用它吗?我正在使用PHPWKHTMLtoPDF包装器版本1.2.6-dev,如果这有助于WKHTMLtoPDF的最新版本,因为最新版本的PHPWKHTMLtoPDF使用名称空间,我们正在使用CodeIgniter 2.x-dev,它不支持它们(或打得好不能记住).

    // Create document PDF
    $pdf = new $this->wkhtmltopdf;

    // Locate WkHtmlToPdf executable for Windows
    if( $pdf->getIsWindows() ) 
    {
        $pdf->setOptions( array( 'binPath' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe', 
                                 'no-outline',
                                 'encoding' => 'UTF-8',
                                 'margin-top'    => 30,
                                 'margin-right'  => 20,
                                 'margin-bottom' => 30,
                                 'margin-left'   => 20,

                                 // Default page options
                                 'disable-smart-shrinking',
                                 'user-style-sheet' => 'pdf.css',
                                 'header-html' => dirname(__FILE__) . '\..\views\wkhtmltopdf\header.html'
        ) );
    }

    // Generate document fields
    $docInputs = $this->generate_inputs( $inputs, json_decode( $this->load->file( APPPATH . '/mapping/' . $document['mapping'], TRUE ), TRUE ) );

    // Merge document fields into HTML exported Word files
    $docHTML = $this->parser->parse( 'docs/' . $document['html'], $docInputs, TRUE );

    // Add HTML as page, along with option for page header
    $pdf->addPage( $docHTML, array( 'header-center' => '[[page]]',
                                    'header-spacing' => '10',
                                    'header-font-name' => 'Times New Roman'
    ) ); 
Run Code Online (Sandbox Code Playgroud)

mtp*_*ltz 28

您需要将<!DOCTYPE html>头文件添加到版本0.12的WKHTMLtoPDF 问题#46

  • 天哪,我在找到这个之前失去的时间:(TY (2认同)

Don*_* V. 5

我发布这个答案是因为这发生在我身上,这也可能是一个原因。

我也注意到你是否将标题 css 设置为这个。它不会显示标题。

html{
   width: 100%;
   height: 100%;
}
Run Code Online (Sandbox Code Playgroud)