Convert from HTML to PDF in CSharp VB and ASP.NET with a Free 3rd Party Library

Converting from html to pdf is not an easy task. There are some tools that can do that, but most of them cost thousands of dollars. SelectPdf offers a Community Edition (FREE) of the powerful Html To Pdf Converter for .NET that can be found in the full featured pdf library.

 
 
 
 
 
3.6 Star
(59)
52,991 times
Add to favorites
5/10/2019
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
VB.NET
<!DOCTYPE html>
<html>
    <head>
        <title>Test document for Select.Pdf Sample</title>
    </head>
    <body>
        <h1>Select.Pdf for .NET - Start Conversion from Javascript</h1>
        <p>
            This is a sample page that will demonstrate how a html to pdf conversion can be triggered from a javascript call using Select.Pdf Library for .NET.
            <br />
            The page increments a timer until it reaches 3 and then it calls the conversion from javascript. 
            If the conversion is manually started from javascript, the timer below should be 3 in pdf. If the conversion is automatically started when the page loads, the timer below should be 1 in pdf.
        </p>
        <p>
            Library version: <span id="idVersion"></span><br />
            Timer: <span id="idTimer"></span><br />
        </p>

        <script type="text/javascript" src="jquery.js"> </script>
        <script type="text/javascript">
            var timer = 0;

            function incrementTimer() {
                timer = timer + 1;

                if (typeof (selectpdf) == "object") {
                    $("*#idVersion").html(selectpdf.version);
                }
                else {
                    $("*#idVersion").html("Not in converter.");
                }
                $("*#idTimer").text(timer);

                if (timer == 3) {
                    // 3 seconds elapsed - start conversion
                    if (typeof (selectpdf) == "object") {
                        selectpdf.start();
                    }
                }
                else {
                    // wait another second
                    setTimeout("incrementTimer()", 1000);
                }

            }

            $(document).ready(function () {
                incrementTimer();
            });
        </script>
    </body>
</html>