We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to convert HTML code to pdf ?

Thread ID:

Created:

Updated:

Platform:

Replies:

89490 Aug 26,2009 08:12 AM UTC Aug 27,2009 12:21 PM UTC ASP.NET Web Forms (Classic) 1
loading
Tags: PDF
Julian Bercovici
Asked On August 26, 2009 08:12 AM UTC

Hie.

I would like to know if it's possible to send the HTML source code of a web page for conversion to PDF instead of the URL ?

thanks.


Thiruvenkadam E [Syncfusion]
Replied On August 27, 2009 12:21 PM UTC

Hi Iulian,

Thank you for your interest in Syncfusion products.

Convert HTML code to pdf

We can able to convert HTML code to pdf using FromString(string html, ImageType type, int width, int height) method.

Kindly refer the below code snippet which helps to convert HTML code to pdf.


string htmlCode = "<html> <body> <font color='#FF0000F'>PDF stands for Portable Document Format </font> </body> </html>";
//Create a PDF document
PdfDocument doc = new PdfDocument();
//Add a page
PdfPage page = doc.Pages.Add();
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = -1;
float height = -1;
//Calculates the height and width of the pdf image
AspectRatio dimension = AspectRatio.None;
//Create a html converter.
HtmlConverter html = new HtmlConverter();
//Convert html to image
Image image = html.FromString(htmlCode, Path.GetFullPath(txtUrl.Text), ImageType.Metafile, (int)width, (int)height, dimension);
//Create a pdf metafile.
PdfMetafile mf = new PdfMetafile(image as Metafile);
mf.Quality = 100;
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
//Draw the metafile
mf.Draw(page, new Point(0, 0), format);
//Save the document.
doc.Save("Sample.pdf");


Please do find the sample from the below specified location which demonstrates how to convert HTML code to pdf and let me know if this helps,

http://files.syncfusion.com/support/PDF.Windows/F89490/HtmltoPdf.zip

Regards,
Thiru

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;