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:
1 2 3 |
$target = \Zend_Pdf_Action_URI :: create( $baseUrl ); //set url $annotation = \Zend_Pdf_Annotation_Link :: create(x1, $this->y + 10, x2, $this->y - 5, $target ); // set x,y accordingly $page->attachAnnotation( $annotation ); |
Any doubts? If so, do not hesitate to mention them in the Comments section below. I’d be happy to help you out.
Also, please share the post with the Magento Community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
2 Comments
Where we add title name ?
Hey Zargam,
Adding link to pdf is not related to title.