Convert from Html To Pdf in Vb.Net

 

There are many solutions that can convert html to pdf. However they have different effects. Some converters are quick and free, but many can export only simple html webpages without dynamic images or links, while other converters, like ExpertPdf, can export complex webpages to PDF. The simplest solution to convert from html to pdf in vb.net is the code below.


VB.NET code sample

    Dim pdfConverter As PdfConverter = New PdfConverter

    pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4
    pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal
    pdfConverter.PdfDocumentOptions.ShowHeader = true
    pdfConverter.PdfDocumentOptions.ShowFooter = true
    pdfConverter.PdfDocumentOptions.LeftMargin = 5
    pdfConverter.PdfDocumentOptions.RightMargin = 5
    pdfConverter.PdfDocumentOptions.TopMargin = 5
    pdfConverter.PdfDocumentOptions.BottomMargin = 5
    pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true

    pdfConverter.PdfDocumentOptions.ShowHeader = false
    'pdfConverter.PdfHeaderOptions.HeaderText = "Sample header: " + TxtURL.Text;
    'pdfConverter.PdfHeaderOptions.HeaderTextColor = Color.Blue;
    'pdfConverter.PdfHeaderOptions.HeaderDescriptionText = string.Empty;
    'pdfConverter.PdfHeaderOptions.DrawHeaderLine = false;

    pdfConverter.PdfFooterOptions.FooterText = ("Sample footer: "  _
                + (TxtURL.Text + ". You can change color, font and other options"))
    pdfConverter.PdfFooterOptions.FooterTextColor = Color.Blue
    pdfConverter.PdfFooterOptions.DrawFooterLine = false
    pdfConverter.PdfFooterOptions.PageNumberText = "Page"
    pdfConverter.PdfFooterOptions.ShowPageNumber = true

    'pdfConverter.LicenseKey = "put your serial number here"
    Dim downloadBytes() As Byte = pdfConverter.GetPdfFromUrlBytes(url)
    Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response

    response.Clear
    response.AddHeader("Content-Type", "binary/octet-stream")
    response.AddHeader("Content-Disposition", ("attachment; filename="  _
                    + (downloadName + ("; size=" + downloadBytes.Length.ToString))))
    response.Flush
    response.BinaryWrite(downloadBytes)
    response.Flush
    response.End
    




Latest News

Oct 4th, 2017

ExpertPdf HtmlToPdf Converter v11.1.0 was released.

read more
Mar 27th, 2017

ExpertPdf Pdf To Image Converter v1.2.0 was released.

read more

Pdf Library for .NET

ExpertPDF Html To Pdf Converter

Html to Pdf asp.net

"HTML to PDF is a quality component that is clearly valuable to any Web developer in need of an easy and flexible way to generate PDF files."

Steve C. Orr - MCSD, Microsoft MVP in ASP.NET

more testimonials
customers list

With ExpertPdf you can convert html to pdf in .NET.

Professional aspx to pdf converter, ExpertPdf works with Microsoft Azure if used in a virtual machine or a cloud service.

Copyright 2017. Outside Software Inc.