【问题标题】:Zend_Pdf Add text link to pdf pageZend_Pdf 添加文本链接到 pdf 页面
【发布时间】:2010-11-14 06:57:58
【问题描述】:

是否可以在 Zend_PDF 页面中添加锚文本(链接)? 我无法在 Zend_Pdf 在线手册或阅读代码中找到有关此的任何信息,所以我想这是不可能的。

如果有办法,请指教!

谢谢!

【问题讨论】:

    标签: php zend-framework pdf zend-pdf


    【解决方案1】:

    禁用边框:

    ...
    $target = Zend_Pdf_Action_URI::create('http://example.com');
    $annotation = Zend_Pdf_Annotation_Link::create(0,0,100,100,$target);
    $annotation->getResource()->Border = new Zend_Pdf_Element_Array([
        new Zend_Pdf_Element_Numeric(0),
        new Zend_Pdf_Element_Numeric(0),
        new Zend_Pdf_Element_Numeric(0)
    ]);
    $pdf->pages[0]->attachAnnotation($annotation);
    ...
    

    【讨论】:

    • 谢谢,$annotation->getResource()->Border = new Zend_Pdf_Element_Array();为我工作:)
    【解决方案2】:

    以下代码将创建一个空白页面,其左下角有一个包含超链接的可点击区域:

    $pdf = new Zend_Pdf();
    $pdf->pages[0] = new Zend_Pdf_Page( Zend_Pdf_Page::SIZE_A4 );
    $target = Zend_Pdf_Action_URI :: create( 'http://example.com' );
    $annotation = Zend_Pdf_Annotation_Link :: create( 0, 0, 100, 100, $target );
    $pdf->pages[0]->attachAnnotation( $annotation );
    $pdf->save( 'test.pdf' );
    

    上述 sn-p 已使用 Zend Framework 1.10.7 进行了测试,但应该适用于 Zend Framework 1.9.7 以后的所有版本。

    【讨论】:

      【解决方案3】:

      这是不可能的 - 我自己尝试做类似的事情,不幸的是不得不求助于FPDF,它不如 Zend_Pdf。

      我研究了在 Zend_Pdf 中实现链接功能,但结构过于复杂,以至于我不得不花费大量时间来寻找解决方案。

      【讨论】:

      【解决方案4】:

      我一直在努力解决边界问题,并通过一个相当简单的 hack 解决了它:

      echo str_replace('/Annot /Subtype /Link', '/Annot /Subtype /Link /Border[0 0 0]', $pdf->render());
      

      这将使链接类型的所有注释都没有边框。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-15
        • 2015-09-15
        • 1970-01-01
        • 2014-07-13
        • 2012-03-19
        • 1970-01-01
        • 2018-10-19
        相关资源
        最近更新 更多