p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/asp-net-2-0-professional-215/)
-   -   Convert html to pdf file by using asp.net in c# (http://p2p.wrox.com/asp-net-2-0-professional/62811-convert-html-pdf-file-using-asp-net-c.html)

dey.susanta.kolkata October 11th, 2007 05:25 AM

Convert html to pdf file by using asp.net in c#
Convert html to pdf file by using asp.net in c#[?]

BrendaBessi December 12th, 2013 05:02 AM

Re: Convert html to pdf file by using asp.net in c#
Here is a simple and straightforward way to convert html to pdf file in .NET:

// Convert HTML document to a PDF document.
DocumentModel.Load("Document.html", LoadOptions.HtmlDefault).Save("Document.pdf", SaveOptions.PdfDefault);

The code uses this C# Word component.

hiqpdf July 28th, 2016 08:47 AM

HTML to PDF Library for .NET
You can get the most accurate HTML to PDF conversion with HiQPdf HTML to PDF Converter for .NET offers the. For small tasks you can use the free HTML to PDF .NET library in your applications. The free version doesn't offer all the features of the full library but it is enough to create small PDFs. The C# sample code for converting HTML to PDF in ASP.NET is:


protected void buttonConvertToPdf_Click(object sender, EventArgs e)
    // create the HTML to PDF converter
    HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

    // set browser width
    htmlToPdfConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text);

    // set browser height if specified, otherwise use the default
    if (textBoxBrowserHeight.Text.Length > 0)
        htmlToPdfConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text);

    // set HTML Load timeout
    htmlToPdfConverter.HtmlLoadedTimeout = int.Parse(textBoxLoadHtmlTimeout.Text);

    // set PDF page size and orientation
    htmlToPdfConverter.Document.PageSize = GetSelectedPageSize();
    htmlToPdfConverter.Document.PageOrientation = GetSelectedPageOrientation();

    // set the PDF standard used by the document
    htmlToPdfConverter.Document.PdfStandard = checkBoxPdfA.Checked ? PdfStandard.PdfA : PdfStandard.Pdf;

    // set PDF page margins
    htmlToPdfConverter.Document.Margins = new PdfMargins(5);

    // set whether to embed the true type font in PDF
    htmlToPdfConverter.Document.FontEmbedding = checkBoxFontEmbedding.Checked;

    // set triggering mode; for WaitTime mode set the wait time before convert
    switch (dropDownListTriggeringMode.SelectedValue)
        case "Auto":
            htmlToPdfConverter.TriggerMode = ConversionTriggerMode.Auto;
        case "WaitTime":
            htmlToPdfConverter.TriggerMode = ConversionTriggerMode.WaitTime;
            htmlToPdfConverter.WaitBeforeConvert = int.Parse(textBoxWaitTime.Text);
        case "Manual":
            htmlToPdfConverter.TriggerMode = ConversionTriggerMode.Manual;
            htmlToPdfConverter.TriggerMode = ConversionTriggerMode.Auto;

    // set header and footer

    // set the document security
    htmlToPdfConverter.Document.Security.OpenPassword = textBoxOpenPassword.Text;
    htmlToPdfConverter.Document.Security.AllowPrinting = checkBoxAllowPrinting.Checked;

    // set the permissions password too if an open password was set
    if (htmlToPdfConverter.Document.Security.OpenPassword != null && htmlToPdfConverter.Document.Security.OpenPassword != String.Empty)
        htmlToPdfConverter.Document.Security.PermissionsPassword = htmlToPdfConverter.Document.Security.OpenPassword + "_admin";

    // convert HTML to PDF
    byte[] pdfBuffer = null;

    if (radioButtonConvertUrl.Checked)
        // convert URL to a PDF memory buffer
        string url = textBoxUrl.Text;

        pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
        // convert HTML code
        string htmlCode = textBoxHtmlCode.Text;
        string baseUrl = textBoxBaseUrl.Text;

        // convert HTML code to a PDF memory buffer
        pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);

    // inform the browser about the binary data format
    HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

    // let the browser know how to open the PDF document, attachment or inline, and the file name
    HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=HtmlToPdf.pdf; size={1}",
        checkBoxOpenInline.Checked ? "inline" : "attachment", pdfBuffer.Length.ToString()));

    // write the PDF buffer to HTTP response

    // call End() method of HTTP response to stop ASP.NET page processing

evopdf September 6th, 2016 08:33 AM

You can obtain great html to pdf conversion results with evo html to pdf for .net. You can test it online and find detailed code samples at http://www.evopdf.com/demo/

E. B September 19th, 2016 08:20 AM

Free HTML to PDF Library for .NET
You can download a good free html to pdf sample project for ASP.NET in C# that you can build and run on your computer.

All times are GMT -4. The time now is 03:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.