Zend_Pdf 添加文本链接到PDF页面

7

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

如果有方法,请建议!

谢谢!

4个回答

6

禁用边框:

...
$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(); 对我有用 :) - Hiren Soni

3
以下代码将创建一个空白页面,底部左侧有一个可点击区域,其中包含一个超链接:
$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' );

上面的代码片段已经在Zend Framework 1.10.7上进行了测试,但应该适用于从1.9.7版本开始的所有Zend Framework版本。


1

我一直在为边框问题苦苦挣扎,最终通过一个相当简单的技巧解决了它:

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

这将使所有类型为“link”的注释不具有边框。


1

这是不可能的 - 我曾经尝试过类似的事情,不幸的是不得不使用 FPDF,它不如 Zend_Pdf 好用。

我研究了在 Zend_Pdf 中实现链接功能,但由于时间有限,结构过于复杂,无法找到解决方案。


1
随着Zend Framework 1.9的发布和对注释的支持,现在可以实现这一点。更多信息请访问http://framework.zend.com/manual/en/zend.pdf.interactive-features.html#zend.pdf.pages.interactive-features.annotations - David Snabel-Caunt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接