Articles in this section
Category / Section

How to avoid text and image splitting when converting HTML to PDF?

2 mins read

The Syncfusion HTML to PDF for .NET is used for converting webpages, SVG, MHTML, and HTML to PDF. Using this library, you can avoid text and image splitting across the WinForms PDF pages while converting HTML to PDF.

Steps to avoid text and image splitting on HTML to PDF conversion:

  1. Create a new C# Windows Forms application project.

Create a windows form project in WinForms PDF

  1. Install the Syncfusion.HtmlToPdfConverter.QtWebKit.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.

install nuget packages in WinForms PDF

  1. Copy the QtBinaries folder from the HtmltoPdfConverter NuGet package installed location to the project folder that contains the HTMLtoPDF_Sample.csproj file.

copy the qtbinaries folder in WinForms PDF

paste the qtbinaries folder to project location in WinForms PDF.

 

  1. Disable the SplitTextLines and SplitImages properties available in the WebKitConverterSettings instance to avoid the text and image splitting during the HTML to PDF conversion. Find the sample and code sample as follows.

C#

//Initialize the HTML to PDF converter
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
 
//Initialize WebKitConverterSetttings
WebKitConverterSettings settings = new WebKitConverterSettings();
 
//Set WebKit path
settings.WebKitPath = @"/QtBinaries/";
 
//Set the SplitTextLines property
settings.SplitTextLines = false;
 
//Set the SplitImages property
settings.SplitImages = false;
 
//Assign WebKit settings to HTML converter
htmlConverter.ConverterSettings = settings;
 
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert("input.html");
 
//Save and close the PDF document
document.Save("Output.pdf");
document.Close(true);
 

 

 

Screenshot of the SplitTextLines and SplitImages property enabled

documentenable output in WinForms PDF

 

Screenshot of the SplitTextLines and SplitImages property disabled document

                  disable output in WinForms PDF

A complete working sample can be downloaded from the HTMLtoPDF_Sample.zip

Take a moment to peruse the documentation for Converting HTML to PDF. You will find various options for URL to PDF, HTML string to PDF, and hyperlinks.

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

An online sample link for Converting HTML to PDF.

Conclusion

I hope you enjoyed learning about how to avoid text and image splitting when converting HTML to PDF.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

 

For current customers, you can check out our WinForms 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 WinForms PDF and other WinForms components.

 

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-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 sign in to leave a comment
Access denied
Access denied