mPDF不会在页脚中打印页码

时间:2018-09-11 22:27:48

标签: mpdf

我们在WordPress网站上使用了mPDF插件,该插件运行良好,但似乎无法在页脚中使用简单的页面编号。我们参考了主要文档(https://mpdf.github.io/paging/page-numbering.html),并尝试了各种示例,但都没有碰到运气。当我们添加$mpdf->setFooter('{PAGENO}');时,会看到页脚行出现在PDF中-但没有页码。这是我们的全部功能:

function savePDFFile($fileName, $page) {

    ob_start();
    include_once($_SERVER['DOCUMENT_ROOT'] . '/mpdf/mpdf.php');

    $postdata = http_build_query(
            array(
                'postSessionData' => $_SESSION[$page],
            )
    );

    $opts = array('http' =>
        array(
            'method' => 'POST',
            'header' => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );

    try {
        $context = stream_context_create($opts);

        $mpdf = new mPDF('utf-8', 'Letter', 0, '', 12, 11, 13, 9, 12, 13);
        $mpdf->ignore_invalid_utf8 = true;
        $mpdf->autoLangToFont = true;
        $mpdf->setAutoTopMargin = 'stretch';
        $mpdf->setAutoBottomMargin = 'stretch';
        $mpdf->setFooter('{PAGENO}');
        $mpdf->WriteHTML('');
        $html = file_get_contents('http://' . $_SERVER['SERVER_NAME'] . '/print-pdf-html/' . $page . '.php', false, $context);

        ob_clean();
        $mpdf->autoLangToFont = true;


        $mpdf->WriteHTML(utf8_encode($html));
        $mpdf->Output('applications/' . $fileName . '.pdf', 'F');
    } catch (Exception $e) {
        file_put_contents(get_template_directory() . '/error-create-pdf.txt', print_r($e, true));
    }

}

0 个答案:

没有答案