How to avoid text and image splitting when converting HTML to PDF?
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:
- Create a new C# Windows Forms application project.
- Install the Syncfusion.HtmlToPdfConverter.QtWebKit.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.
- Copy the QtBinaries folder from the HtmltoPdfConverter NuGet package installed location to the project folder that contains the HTMLtoPDF_Sample.csproj file.
- 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
document
Screenshot of the SplitTextLines and SplitImages property disabled document
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!