Category / Section
How to relink hyperlinks in the HTML to PDF Converter file in WebForms ?
2 mins read
To relink hyperlinks from HTML to PDF, convert the HTML to PDF by using the HtmlToPdfResult and then append the PDF file that has to be navigated. Hyperlinks are converted to the PdfDocumentLinkAnnotation in PDF. So, the file can be loaded and added to the page in the PdfDestination by using the PdfDocumentLinkAnnotation.
The following code example displays the same.
- HTML TO PDF Conversion.
C#
using (HtmlConverter htmlConverter = new HtmlConverter()) { htmlConverter.EnableHyperlinks = true; //Converts HTML to PDF. using (HtmlToPdfResult result = htmlConverter.Convert(path, ImageType.Metafile, (int)width, -1, Syncfusion.HtmlConverter.AspectRatio.None)) { if (result.RenderedImage == null) return; // Draws metafile in the PdfPage. result.Render(page, metafileFormat); } }
- Append the Document and Relink by using the PdfDocumentLinkAnnotation.
C#
//Loads the document to be appended. PdfLoadedDocument document = new PdfLoadedDocument (Bookmark.pdf")); pdfDoc.Append(document); //Adds the Document Link. for (int i = 0; i < pdfDoc.Pages[0].Annotations.Count; i++) { PdfDocumentLinkAnnotation annotation = pdfDoc.Pages[0].Annotations[i] as PdfDocumentLinkAnnotation; annotation.Destination = new PdfDestination(pdfDoc.Pages[i]); }
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/RelinkHtmltoPdf1294067253.zip