Last active
April 7, 2022 18:25
-
-
Save groupdocs-com-kb/ecac1f8840968d012e2d2ee554aadb8d to your computer and use it in GitHub Desktop.
How to Convert HTML to PDF using C#. For more information, please follow link: https://kb.groupdocs.com/conversion/net/how-to-convert-html-to-pdf-using-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using GroupDocs.Conversion.Options.Convert; | |
namespace ConvertHtmlToPdfUsingCSharp | |
{ | |
class Program | |
{ | |
public static void Main(string[] args) // Main function to convert HTML to PDF using C# | |
{ | |
// Remove the watermark in output PDF document by adding license | |
string licensePath = "GroupDocs.Conversion.lic"; | |
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License(); | |
lic.SetLicense(licensePath); | |
// Load the source HTML file for conversion to PDF | |
var converter = new GroupDocs.Conversion.Converter("sample.html"); | |
// Set the convert options for PDF document | |
var convertOptions = new PdfConvertOptions() | |
{ | |
Height = 500, | |
Width = 500, | |
Dpi = 100, | |
PageNumber = 1, | |
PagesCount = 1 | |
}; | |
// Convert and save the HTML in PDF format | |
converter.Convert("converted.pdf", convertOptions); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment