Articles in this section
Category / Section

How to preserve internal links in HTML when converting to PDF?

5 mins read

The Syncfusion HTML to PDF converter is a .NET library for converting webpages, SVG, MHTML, and HTML to PDF using C#. It is reliable and accurate. The result preserves all graphics, images, texts, fonts, and the layout of the original HTML document or webpage.

Using this library, you can automatically convert all the internal links from HTML to internal documents links in PDF.

Steps to add internal document links in HTML to PDF conversion:

  1. Create a new .NET console application project.

Create a new .NET Console application project

Configure new project with project name

  1. Select the .NET Framework for your application.

Select the framework for the application

  1. Install the Syncfusion.HtmlToPdfConverter.Net.Windows NuGet package as a reference to your .NET application from NuGet.org.

NuGet package reference

  1. Include the following namespaces in Program.cs file.

C#

using Syncfusion.HtmlConverter;
using Syncfusion.Pdf;

 

  1. Include the following code snippet in Program.cs file to preserve internal links in HTML to PDF conversion.

C#

string url = Path.GetFullPath("../../../Data/input.html");
 
//Initialize HTML to PDF converter 
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
 
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
 
//Enable hyperlink
blinkConverterSettings.EnableHyperLink = true;
 
//Assign Blink converter settings to HTML converter
htmlConverter.ConverterSettings = blinkConverterSettings;
 
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert(url);
 
FileStream fileStream = new FileStream("Sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite);
 
//Save and close the PDF document 
document.Save(fileStream);
document.Close(true);
 

 

A complete sample to preserve internal links in HTML when converting to PDF can be downloaded from InternalLinks_HTMLToPDF.zip.

 

By executing the sample, you will get the PDF document as follows.

output PDF screenshot.

 

Take a moment to peruse the documentation, where you can find converting HTML pages to PDF document along with respective customization options and features.

Refer here to explore the rich set of Syncfusion Essential PDF features.

An online sample link for Converting HTML to PDF.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

 Conclusion

I hope you enjoyed learning about how to preserve internal links in HTML when converting to PDF.

You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF Example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied