locked
How to save the visual+data of an aspx web page as PDF in a database RRS feed

  • Question

  • User1922139044 posted

    Hello.

    For one of my project, .NET web site (ASPX), the users have to fill an annual declaration form and click a submit button.

    We've always only been saving the values in an SQL Server database.

    But this year, I have been requested, for archiving purpose, to save the [Visual + Data] of the web page as seen on the browser in a PDF format in the database.

    So when the user clicks the "Submit" button, in addition of saving the data in the database, I would also need to save the [Visual + Data].  

    Is that even possible to do?

    I've been searching on Google but I can't find anything, maybe I don't search the write terms/words.

    Thank you for helping.

    EDIT : My web page has to remain a web form and not a Fillable PDF document.

    Monday, January 20, 2020 4:26 PM

All replies

  • User475983607 posted

    Is that even possible to do?

    Find a PDF library for .NET.  NuGet is easiest route.

    Monday, January 20, 2020 4:29 PM
  • User288213138 posted

    Hi DoumB21,

    for archiving purpose, to save the [Visual + Data] of the web page as seen on the browser in a PDF format in the database.

    So when the user clicks the "Submit" button, in addition of saving the data in the database, I would also need to save the [Visual + Data].  

    According to your description, I couldn’t understand your requirement clearly.

    What does [visual + data] mean?

    If you want to save the web page as pdf file, you can try to use ITextsharp.

    Here a demo for you as a reference:

     <div style="font-family: Arial">This is a test page</div>
            <div>
                <table border="1" width="100">
                    <tr>
                        <td>Name</td>
                        <td>Age</td>
                    </tr>
                    <tr>
                        <td>John</td>
                        <td>11</td>
                    </tr>
                    <tr>
                        <td>Sam</td>
                        <td>13</td>
                    </tr>
                    <tr>
                        <td>Tony</td>
                        <td>12</td>
                    </tr>
                </table>
            </div>
            <div>
                <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
            </div>
    
    
    <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation = "false" %>
    using System.IO; using iTextSharp.text; using iTextSharp.text.html.simpleparser; using iTextSharp.text.pdf; protected void btnExport_Click(object sender, EventArgs e) { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); this.Page.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); }

    Best regards,

    Sam

    Tuesday, January 21, 2020 2:28 AM