Winnovative Software Solutions HTML to PDF Converter


 HTML to PDF Converter for .NET - Free Converter Application - PDF Creator
 PDF Merge/Split - PDF Security - RTF to PDF Converter - Excel Library - Charts

 
Skip Navigation Links
 

Getting Started With the Winnovative HTML to PDF Converter for .NET Demo

In the quick online demo below you can see the main capabilities of the HTML to PDF Converter. You can enter the URL of any web page accessible from Internet and press the Convert button to render the web page either to a PDF document or to an image in the preferred format.

The full C# and VB.NET source code for this sample is available in the downloaded archive under the AspNet_GettingStarted_CS and AspNet_GettingStarted_VB samples.

Note: The online demo limits the number of pages of the generated PDF document to about 20 pages in A4 Portrait format or 40 pages in A4 Landscape format. The downloaded evaluation version does not have this limitation.
HTML to PDF Converter

HTML to PDF Conversion - Live Demo

Select HTML source:
Enter URL:    

C# Code From This Sample To Convert a URL to PDF

1:     /// <summary>
2:     /// Convert the HTML code from
                        the specified URL to a PDF document and send the 
3:     /// document as
                        an attachment to the browser
4:     /// </summary>
5:     private void ConvertURLToPDF()
6:     {
7:         string urlToConvert = textBoxWebPageURL.Text.Trim();
8:         bool selectablePDF = radioConvertToSelectablePDF.Checked;
9:  
10:         // Create the PDF converter.
                        Optionally you can specify the virtual browser 
11:         // width as
                        parameter. 1024 pixels is default, 0 means autodetect
12:         PdfConverter pdfConverter = 
                        new PdfConverter();
13:         // set the
                        license key
14:         pdfConverter.LicenseKey = 
                        "P38cBx6AWW7b9c81TjEGxnrazP+J7rOjs+9omJ3TUycauK+cLWdrITM5T59hdW5r";
15:         // set the
                        converter options
16:         pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
17:         pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
18:         pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
19:         pdfConverter.PdfDocumentOptions.ShowHeader = false;
20:         pdfConverter.PdfDocumentOptions.ShowFooter = false;
21:         // set to generate
                        selectable pdf or a pdf with embedded image
22:         pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = selectablePDF;
23:  
24:         // Performs the conversion
                        and get the pdf document bytes that you can further 
25:         // save to
                        a file or send as a browser response
26:         byte[] pdfBytes = pdfConverter.GetPdfFromUrlBytes(urlToConvert);
27:  
28:         // send the PDF document
                        as a response to the browser for download
29:         System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
30:         response.Clear();
31:         response.AddHeader(
                        "Content-Type", "binary/octet-stream");
32:         response.AddHeader("Content-Disposition",
33:             "attachment;
                        filename=ConversionResult.pdf; size=" + pdfBytes.Length.ToString());
34:         response.Flush();
35:         response.BinaryWrite(pdfBytes);
36:         response.Flush();
37:         response.End();
38:     }

VB.NET Code From This Sample To Convert a URL to PDF

1: ''' <summary>
2:     ''' Convert the HTML code from
                        the specified URL to a PDF document and send the 
3:     ''' document as
                        an attachment to the browser
4:     ''' </summary>
5:     ''' <remarks></remarks>
6:     Private Sub ConvertURLToPDF()
7:  
8:         Dim urlToConvert As String = textBoxWebPageURL.Text.Trim()
9:         Dim selectablePDF As Boolean = radioConvertToSelectablePDF.Checked
10:  
11:         ' Create the
                        PDF converter. Optionally you can specify the virtual browser 
12:         ' width as parameter. 1024
                        pixels is default, 0 means autodetect
13:         Dim pdfConverter As PdfConverter = New PdfConverter()
14:         ' set the license key
14:         pdfConverter.LicenseKey = 
                        "P38cBx6AWW7b9c81TjEGxnrazP+J7rOjs+9omJ3TUycauK+cLWdrITM5T59hdW5r";
16:         ' set the converter options
17:         pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4
18:         pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal
19:         pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait
20:         pdfConverter.PdfDocumentOptions.ShowHeader = False
21:         pdfConverter.PdfDocumentOptions.ShowFooter = False
22:         ' set to generate selectable
                        pdf or a pdf with embedded image
23:         pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = selectablePDF
24:  
25:         ' Performs
                        the conversion and get the pdf document bytes that you can further 
26:         ' save to a file or send
                        as a browser response
27:         Dim pdfBytes As Byte() = pdfConverter.GetPdfFromUrlBytes(urlToConvert)
28:  
29:         ' send the
                        PDF document as a response to the browser for download
30:         Dim Response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
31:         Response.Clear()
32:         Response.AddHeader("Content-Type", "binary/octet-stream")
33:         Response.AddHeader(
                        "Content-Disposition", "attachment; filename=ConversionResult.pdf;
                            size=" & pdfBytes.Length.ToString())
34:         Response.Flush()
35:         Response.BinaryWrite(pdfBytes)
36:         Response.Flush()
37:         Response.End()
38:     End Sub

C# Code From This Sample To Convert a HTML String To PDF

1: /// <summary>
2:     /// Convert the specified HTML
                        string to a PDF document and send the 
3:     /// document as
                        an attachment to the browser
4:     /// </summary>
5:     private void ConvertHTMLStringToPDF()
6:     {
7:         string htmlString = textBoxHTMLCode.Text;
8:         string baseURL = textBoxBaseURL.Text.Trim();
9:         bool selectablePDF = radioConvertToSelectablePDF.Checked;
10:  
11:         // Create the
                        PDF converter. Optionally you can specify the virtual browser 
12:         // width as parameter.
                        1024 pixels is default, 0 means autodetect
13:         PdfConverter pdfConverter = new PdfConverter();
14:         // set the license key
14:         pdfConverter.LicenseKey = 
                        "P38cBx6AWW7b9c81TjEGxnrazP+J7rOjs+9omJ3TUycauK+cLWdrITM5T59hdW5r";
16:         // set the converter options
17:         pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
18:         pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
19:         pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
20:         pdfConverter.PdfDocumentOptions.ShowHeader = false;
21:         pdfConverter.PdfDocumentOptions.ShowFooter = false;
22:         // set to generate selectable
                        pdf or a pdf with embedded image
23:         pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = selectablePDF;
24:  
25:         // Performs
                        the conversion and get the pdf document bytes that you can further 
26:         // save to a file or send
                        as a browser response
27:         //
28:         // The baseURL parameter
                        helps the converter to get the CSS files and images
29:         //
                        referenced by a relative URL in the HTML string. This option has efect only // if
                        the HTML string contains a valid HEAD tag.
30:         // The converter will automatically
                        inserts a <BASE HREF="baseURL"> tag. 
31:         byte[] pdfBytes = null;
32:         if (baseURL.Length > 0)
33:             pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString, baseURL);
34:         else
35:             pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString);
36:  
37:         // send the
                        PDF document as a response to the browser for download
38:         System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
39:         response.Clear();
40:         response.AddHeader("Content-Type", "binary/octet-stream");
41:         response.AddHeader(
                        "Content-Disposition",
42:             "attachment; filename=ConversionResult.pdf;
                        size=" + pdfBytes.Length.ToString());
43:         response.Flush();
44:         response.BinaryWrite(pdfBytes);
45:         response.Flush();
46:         response.End();
47:     }

VB.NET Code From This Sample To Convert HTML String To PDF

1: ''' <summary>
2:     ''' Convert the specified HTML
                        string to a PDF document and send the 
3:     ''' document as
                        an attachment to the browser
4:     ''' </summary>
5:     ''' <remarks></remarks>
6:     Private Sub ConvertHTMLStringToPDF()
7:  
8:         Dim htmlString As String = textBoxHTMLCode.Text
9:         Dim baseURL As String = textBoxBaseURL.Text.Trim()
10:         Dim selectablePDF As Boolean = radioConvertToSelectablePDF.Checked
11:  
12:         ' Create the PDF converter.
                        Optionally you can specify the virtual browser 
13:         ' width as
                        parameter. 1024 pixels is default, 0 means autodetect
14:         Dim pdfConverter As PdfConverter = New PdfConverter()
15:         ' set the license
                        key
14:         pdfConverter.LicenseKey = 
                        "P38cBx6AWW7b9c81TjEGxnrazP+J7rOjs+9omJ3TUycauK+cLWdrITM5T59hdW5r";
17:         ' set the converter
                        options
18:         pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4
19:         pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal
20:         pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait
21:         pdfConverter.PdfDocumentOptions.ShowHeader = False
22:         pdfConverter.PdfDocumentOptions.ShowFooter = False
23:         ' set to generate
                        selectable pdf or a pdf with embedded image
24:         pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = selectablePDF
25:  
26:         ' Performs the conversion
                        and get the pdf document bytes that you can further 
27:         ' save to a
                        file or send as a browser response
28:         '
29:         ' The baseURL
                        parameter helps the converter to get the CSS files and images
30:         ' referenced by a relative
                        URL in the HTML string. This option has efect only ' if the HTML string contains
                        a valid HEAD tag.
31:         ' The converter
                        will automatically inserts a <BASE HREF="baseURL"> tag. 
32:         Dim pdfBytes As Byte() = Nothing
33:         If (baseURL.Length > 0) Then
34:             pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString, baseURL)
35:         Else
36:             pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlString)
37:         End If
38:  
39:         ' send the
                        PDF document as a response to the browser for download
40:         Dim response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
41:         response.Clear()
42:         response.AddHeader("Content-Type", "binary/octet-stream")
43:         response.AddHeader(
                        "Content-Disposition", "attachment; filename=ConversionResult.pdf;
                            size=" & pdfBytes.Length.ToString())
44:         response.Flush()
45:         response.BinaryWrite(pdfBytes)
46:         response.Flush()
47:         response.End()
48:     End Sub

HTML to PDF Converter