Hi Naresh,
Thank you for your interest in Syncfusion products.
Converting an HTML file to PDFWe can able to converting an HTML file to PDF by using FromString(string html, string baseUrl, ImageType type, int width, int height, AspectRatio aspectRatio) method.
Kindly refer the below code snippet which helps to convert an HTML file to PDF.
[c#]
StreamReader reader = new StreamReader(@"..\..\Template.html");
string html = reader.ReadToEnd();
//Create a new pdf document
PdfDocument pdf = new PdfDocument();
//Adds a new pdf page.
PdfPage page = pdf.Pages.Add();
PdfUnitConvertor converter = new PdfUnitConvertor();
float width = converter.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
using (HtmlConverter html = new HtmlConverter())
{
//Renders html from the string to image.
PdfMetafile mf = new PdfMetafile(html.FromString(htmlContent,Path.GetFullPath(@"..\..\Template.html"),ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth) as Metafile);
mf.Quality = 100;
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
//Draws the image.
mf.Draw(page, new PointF(0, 0), format);
// Save the pdf document.
pdf.Save(path);
// Close pdfdocument
pdf.Close(true);
}
Please do find the sample from the below specified location which demonstrates how to convert an HTML file to PDF and let me know if this helps,
http://files.syncfusion.com/support/PDF.Windows/F88814/HtmltoPdf.zipRegards,
Thiru