Skip to content

Instantly share code, notes, and snippets.

Convert HTML String to PDF in C# | HTML String to PDF C#
// This code example demonstrates how to convert an HTML string to a PDF document.
string htmlString = @"<h1>Convert HTML to PDF!</h1><br/><h2>This is Sample Heading!</h2><p>This is first paragraph.</p>";
// Initialize PdfSaveOptions
var options = new PdfSaveOptions();
// Set the background color
options.BackgroundColor = Color.LightSkyBlue;
// Invoke the ConvertHTML method to convert the HTML code to PDF
Converter.ConvertHTML(htmlString, ".", options, @"C:\Files\Output.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment