Export HTML with CheckBox and Image to PDF using iTextSharp in ASP.Net

Last Reply one month ago By pandeyism

Posted one month ago

Thousands of seniors are missing out on new 2019 discounts for not knowing about them...

Just about every senior who likes to save money knows about the standard discounts available at most restaurants and retailers, but what about the ones that are not so well known? The truth is, the everyday senior discounts pale in comparison to some of the special offers available online. But you have to know where to look and you won’t get them unless YOU ASK!  

We have compiled the most recent and best money-saving discounts seniors can take advantage of in 2019 to save up to $6,100! That's right being a senior citizen has its perks. Many seniors are surprised to find they can save thousands by just taking advantage of these new offers.

1. Get A Discount On A New Walk In Tub

Walk in tubs are a perfect addition for seniors living with mobility challenges or anyone worried about fall related injuries. Statistics tell us that falls happen in your bathroom more than any other room in the home.

In fact two-thirds of all bathroom injuries happen near the shower or bath-tub, according to The Center for Disease Control. Most falls typically happen when your stepping over the tub, slipping on a wet floor or when leaning on a glass door that wasn’t designed to support your weight.

A Walk-in tub is an investment in your future a simple modification to your bathroom can change your life. Keeping your independence and dignity, plus peace of mind for your loved ones all ad up to a better quality of life. Right now, Walk-in tub manufacturers all over the country are offering big senior discounts. Visit the walk-in tub website to find discounts and get a free quote on a new Walk-in tub.

(A check box web object here) [I agree]

A digital signature had already sign and convert to an image, it load from a database  to display the e-signed image., its image is in project solution

My question:  How to convert the text, check box, e-sign image as the above from a web page to a pdf file.  Save it in a folder in project solution, use C# and ASP.Net

 

Posted one month ago Modified on one month ago

Hi KatieNgoc,

Refer below sample.

HTML

<div>
    <asp:Image ImageUrl="~/Files/E-Sign.png" runat="server" Height="100px" Width="100px" />
    <br />
    <div runat="server" id="pnlDetails">
        <p>
            1. Get A Discount On A New Walk In Tub</p>
        <p>
            Walk in tubs are a perfect addition for seniors living with mobility challenges
            or anyone worried about fall related injuries. Statistics tell us that falls happen
            in your bathroom more than any other room in the home.</p>
        <p>
            In fact two-thirds of all bathroom injuries happen near the shower or bath-tub,
            according to The Center for Disease Control. Most falls typically happen when your
            stepping over the tub, slipping on a wet floor or when leaning on a glass door that
            wasn't designed to support your weight</p>
        <p>
            A Walk-in tub is an investment in your future a simple modification to your bathroom
            can change your life. Keeping your independence and dignity, plus peace of mind
            for your loved ones all ad up to a better quality of life. Right now, Walk-in tub
            manufacturers all over the country are offering big senior discounts. Visit the
            walk-in tub website to find discounts and get a free quote on a new Walk-in tub.</p>
    </div>
    <asp:CheckBox Text="I Agree" runat="server" ID="chkAgree" />
    <asp:Button ID="btnSave" Text="Save" runat="server" OnClick="Save" />
</div>

Namespaces

C#

using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text.html.simpleparser;

VB.Net

Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.IO

Code

C#

protected void Save(object sender, EventArgs e)
{
    using (FileStream stream = new FileStream(Server.MapPath("~/Files/") + "ImageExport.pdf", FileMode.Create))
    {
        string filePath = "~/Files/" + Path.GetFileName("E-Sign.png");
        byte[] bytes = File.ReadAllBytes(Server.MapPath(filePath));
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);        
        PdfWriter.GetInstance(pdfDoc, stream);
        pdfDoc.Open();
        pdfDoc.Add(new Paragraph("[" + chkAgree.Text + "]"));
        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bytes);
        pdfDoc.Add(img);
        iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc);
        hw.Parse(new StringReader(pnlDetails.InnerText));
        pdfDoc.Close();
        stream.Close();
    }
}

VB.Net

Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
    Using stream As FileStream = New FileStream(Server.MapPath("~/Files/") & "ImageExport.pdf", FileMode.Create)
        Dim filePath As String = "~/Files/" & Path.GetFileName("E-Sign.png")
        Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath(filePath))
        Dim pdfDoc As Document = New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
        PdfWriter.GetInstance(pdfDoc, stream)
        pdfDoc.Open()
        pdfDoc.Add(New Paragraph("[" & chkAgree.Text & "]"))
        Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(bytes)
        pdfDoc.Add(img)
        Dim hw As iTextSharp.text.html.simpleparser.HTMLWorker = New iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc)
        hw.Parse(New StringReader(pnlDetails.InnerText))
        pdfDoc.Close()
        stream.Close()
    End Using
End Sub