【问题标题】:Show a particular page in PDF using DOMPDF使用 DOMPDF 在 PDF 中显示特定页面
【发布时间】:2011-12-12 13:19:15
【问题描述】:

我正在使用 DOMPDF 从 PHP 生成 PDF 文件。效果很好。

但是现在,当我单击生成 PDF 的链接时,我希望它带我到 PDF 的第五页(如果该页面上有内容)。有没有办法做到这一点?

【问题讨论】:

    标签: php pdf pdf-generation dompdf


    【解决方案1】:

    根据this page上贴的源码,可以使用函数Cpdf.openHere

    /**
    * specify where the document should open when it first starts
    */
    function  openHere($style, $a =  0, $b =  0, $c =  0) {
        // this function will open the document at a specified page, in a specified style
        // the values for style, and the required paramters are:
        // 'XYZ'  left, top, zoom
        // 'Fit'
        // 'FitH' top
        // 'FitV' left
        // 'FitR' left,bottom,right
        // 'FitB'
        // 'FitBH' top
        // 'FitBV' left
        $this->numObj++;
        $this->o_destination($this->numObj, 'new', array('page' => $this->currentPage, 'type' => $style, 'p1' => $a, 'p2' => $b, 'p3' => $c));
        $id =  $this->catalogId;
        $this->o_catalog($id, 'openHere', $this->numObj);
    }
    

    【讨论】:

    • 如果您知道第 5 页从哪里开始,这将起作用。在第 5 页内容中添加一些内联脚本,如下所示:<script type="text/php">$cpdf=$pdf->get_cpdf();$cpdf->openHere('Fit');</script>
    • 或者你可以走简单的路线,只需修改 url ...pdf#page=5 就可以了。
    • 再一次,这些似乎都不适用于 OS X 预览应用程序,所以 YMMV。
    猜你喜欢
    • 2013-10-09
    • 2012-02-22
    • 2016-08-08
    • 2021-10-30
    • 1970-01-01
    • 2011-11-21
    • 2013-04-22
    • 2014-07-31
    • 2013-09-13
    相关资源
    最近更新 更多