How to Add Hyperlink in PDF File in Magento 2

Magento is a widely used CMS for starting an online business. Its capability of customization to suit modern business requirements makes it the number one choice of business owners to smoothly run their online store.

One such customization a store owner may require is to add hyperlink in PDF file in Magento 2.

For example, you are sending a PDF file about order details to a customer. Now you may want to add an order tracking link which can be done using the below solution.

Or, you may want to redirect the customer to the external page for additional information and hence add a link for the same.

If you are using a payment gateway integration and want to inform the customer about the security of online payments, you can add a link in the PDF file in Magento 2 about the payment gateway security features.

There can be multiple uses where you would want to add hyperlinks in the PDF file which can be implemented with the solution given here.

Method to Add Hyperlink in PDF File in Magento 2:

$annotation = \Zend_Pdf_Annotation_Link :: create(x1, $this->y + 10, x2, $this->y 5, $target ); // set x,y accordingly
$page->attachAnnotation( $annotation );

Leave a Reply

Your email address will not be published. Required fields are marked *

12 − eleven =