I am using below code to show hyperlink in pdf file but link is not showing.Drawtext method works fine.It means hyperlink code is not working

$pdf = new \Zend_Pdf();
                        $pdf->pages[] = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4);
                        $page = $pdf->pages[0]; // this will get reference to the first page.
                        $style = new \Zend_Pdf_Style();
$target = \Zend_Pdf_Action_URI::create('http://example.com', true);

             $annotation = \Zend_Pdf_Annotation_Link::create($x+250, $this->y-20, $x+400, $this->y-20, $target);
             $page->drawLine($x+250, $this->y-10, $x+350, $this->y - 10);

In my above code line is showing but hyperlink not showing

1 Answer 1

$target = \Zend_Pdf_Action_URI :: create( $baseUrl );
$annotation = \Zend_Pdf_Annotation_Link :: create( 35, $this->y + 10, 100, $this->y - 5, $target );
$page->attachAnnotation( $annotation );

above code will add an area of rectangle where u can click and it ll redirect.

35 is x1 point

100 is x2

this->y is y1 this->y - 5 is y2 in my case

if you want to add a text at that rectangle

$page->drawText($baseUrlText, 35, $this->y, 'UTF-8');

here it ll add a text in that area and therefor it become clickable


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.