Skip navigation
Currently Being Moderated

PDF & ASP.NET Help

Dec 16, 2006 5:10 PM

I am looking for a server side PDF tool that provides various PDF services to ASP.NET applications.

We have a common need to programmatically open and manipulate PDF files in a ASP.NET web application.

Specifically, we want to:

1. With existing PDF files, enter info into text fields on the PDF and
capture that data to write back to a database
2. Create new PDF documents on the server with data from a DB
3. Populate existing PDF form fields with data from a DB

All PDF's are created using Adobe Lifecycle Builder.
 
Replies
  • Currently Being Moderated
    Dec 18, 2006 6:26 PM   in reply to (YodaT)
    Yoda,

    LiveCycle Forms will do what you need, but it is a J2EE application. To use it you need to set up a J2EE application server. If you're willing to do that, you can access it via SOAP using a .NET server using a dll that Adobe provides.

    Jared
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2007 12:01 PM   in reply to (YodaT)
    Can you please provide more details on that.

    Also, can you tell me where I can find a sample for reference.

    Khader.
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2007 9:19 AM   in reply to (YodaT)
    I wrote a test C# web application (with a lot of guidance from a SmartDoc Technologies article and the Adobe "Developing Custom Applications" document) that displays a page which contains a pdf document.  You can display a pre-populated PDF by entering data as html input.  You can also change the data on the PDF, and extract the data and display this information.<br /><br />Download the sample code from the Developing a .NET web application using Adobe LiveCycle Forms article at http://www.smartdoctech.com/articles.aspx.<br /><br />Place your PDF file on the LiveCycle Forms server.  I put mine in D:\Adobe\LiveCycle\template.<br /><br />Create a new web project.<br /><br />Make a reference to the ICSharpCode.SharpZipLib.dll and SoupClient.dll in the sample code bin folder.<br /><br />TESTPAGE2 CODE IS USED TO DISPLAY A BLANK  AND PRE-POPULATED PDF:<br /><br />using  SoapClient;<br />using CM = System.Configuration.ConfigurationManager;<br /><br />protected void Page_Load(object sender, EventArgs e)<br />{<br />    if (Request.QueryString["extract"] == null || Request.QueryString["extract"].Trim().Length == 0)<br />    {<br />        DisplayPDF();<br />    }<br />    else<br />    {<br />        ExtractPdfData();<br />    }<br />}<br /><br />string _SoapEndPoint = "http://your_server_name:8080/jboss-net/services/AdobeFSService";<br /><br />private void DisplayPDF()<br />{<br />    // Create an FSSoapClient object.<br />    FSSoapClient formServer = new FSSoapClient();<br />    formServer.setSoapEndPoint(_SoapEndPoint);<br /><br />    // Declare and populate local variables to pass to renderForm.<br />    String sFormQuery = "Target.pdf"; //Defines the form design to render<br />    String sFormPreference = "PDFForm"; //Defines the preference option<br />    String sContentRootURI = "D:\\Adobe\\LiveCycle\\template\\";<br />    String sTargetURL = "";<br />    String sApplicationWebRoot = "";<br /><br />    byte[] cData;<br /><br />    try<br />    {<br />        if (Request.QueryString["id"] == null || Request.QueryString["id"].Trim().Length == 0)<br />        {<br />            // Do not prepopulate the form.<br />            cData = new byte[0];<br />        }<br />        else<br />        {<br />          // Extract data from database.<br />            cData = GetData(Request.QueryString["id"]);<br />        }<br /><br />        //Call renderForm<br />        IOutputContext myOutputContext = formServer.renderForm(<br />        sFormQuery, //sFormQuery<br />        sFormPreference, //sFormPreference<br />        cData, //cData,<br />        "CacheEnabled=False",//sOptions<br />        null, //sUserAgent,<br />        sApplicationWebRoot, //sApplicationWebRoot<br />        sTargetURL, //sTargetURL<br />        sContentRootURI, //sContentRootURI<br />        null //sBaseURL<br />        );<br /><br />        //Create a byte array. Call the IOutputContext interface's<br />        //getOutputContext method<br />        byte[] cContent = myOutputContext.getOutputContent();<br />        Response.ContentType = "Application/pdf";<br />        Response.AddHeader("Content-Length", cContent.Length.ToString());<br /><br />        //Write a byte stream back to the web browser. Pass the byte array<br />        Response.BinaryWrite(cContent);<br />        Response.End();<br />    }<br />    //Catch a thrown exception<br />    catch (Exception ex)<br />    {<br />        byte[] bArray = (new System.Text.ASCIIEncoding()).GetBytes(ex.Message);<br />        Response.BinaryWrite(bArray);<br />    }<br />}<br /><br />/// <summary><br />/// Extracts data from database and returns an encoded sequence of bytes.<br />/// </summary><br />/// <returns></returns><br />public byte[] GetData(string pgaID)<br />{<br />    StringBuilder sb = new StringBuilder("");<br />    sb.Append("SELECT field as myfieldname, ");<br />    sb.Append("FROM table ");<br />    sb.Append("WHERE condition1 = true ");<br />    sb.Append("AND field_id = ");<br />    sb.Append(pgaID);<br />    sb.Append(" AND condition2 = true");<br /><br />    string sql = sb.ToString();<br /><br />    string conString = CM.ConnectionStrings["OAM_Connection"].ConnectionString;<br />    AseConnection con = new AseConnection(conString);<br />    AseCommand cmd = new AseCommand(sql, con);<br />    cmd.CommandType = CommandType.Text;<br /><br />    AseDataAdapter da = new AseDataAdapter(cmd);<br />    DataSet ds = new DataSet();<br /><br />    try<br />    {<br />        con.Open();<br />        da.Fill(ds, "XML_Root_Name");<br />        ds.DataSetName = "REMOVE";<br />    }<br />    catch<br />    {<br />        throw;<br />    }<br />    finally<br />    {<br />        con.Close();<br />    }<br /><br />    // Convert the dataset to XML.<br />    XmlDataDocument datadoc = new XmlDataDocument(ds);<br />    string dsXML = datadoc.InnerXml;<br /><br />    // Remove root element of Dataset.<br />    if (dsXML.Length > 17)<br />    {<br />        dsXML = dsXML.Remove(0, 8);<br />        dsXML = dsXML.Remove(dsXML.Length - 9);<br />    }<br /><br />    return Encoding.ASCII.GetBytes(dsXML);<br /><br />}<br /><br />TESTPAGE2 ALSO IS CALLED DIRECTLY BY THE PDF.  <br /><br />private void ExtractPdfData()<br />{<br />    try<br />    {<br />        //Create an FSSoapClient object<br />        FSSoapClient formServer = new FSSoapClient();<br />        formServer.setSoapEndPoint(_SoapEndPoint);<br /><br />        // Call processFormSubmission to handle the submitted data. Pass the<br />        // Request object<br />        IOutputContext myOutputContext = formServer.processFormSubmission(Request, "OutputType=0");<br />        //Populate a byte array by calling IOutputContext objects<br />        //getOutContent method<br />        byte[] formOutput = myOutputContext.getOutputContent();<br />        //Create a MemoryStream object<br />        MemoryStream myMemoryStream = new MemoryStream(formOutput);<br />        // Create an XmlDocument object<br />        XmlDocument myDOM = new XmlDocument();<br />        // Load the XML data into the XmlDocument object:<br />        myDOM.Load(myMemoryStream);<br />        // Call getNodeText for each field in the form<br />        String clientName = getNodeText("fieldname1", myDOM);<br />        String question1 = getNodeText("fieldname2", myDOM);<br /><br />        StringBuilder sb = new StringBuilder("");<br />        sb.Append("<h2>You selected:</h2>");<br />        sb.Append("Field 1: " + fieldname1 + "<br>");<br />        sb.Append("Field 2: " + fieldname2 + "<br>");<br /><br />        Response.Write(sb.ToString());<br />    }//End of try statement<br /><br />    catch (Exception ioEx)<br />    {<br />        Response.Write("Exception error is: " + ioEx);<br />    }<br />}<br /><br />// Create the getNodeText custom method<br />private String getNodeText(String nodeName, XmlDocument myDOM)<br />{<br />    //Get the node by name. nodeName is the name of the<br />    //node passed to this method<br />    XmlNodeList nl = myDOM.GetElementsByTagName(nodeName);<br />    XmlNode myNode = nl.Item(0);<br />    return myNode.InnerText;<br />}//End of getNodeText<br /><br />Default.aspx UI CODE, Blank.pdf is used for the initial display - located in web project:<br /><br /><%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><br /><br /><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><br /><html xmlns="http://www.w3.org/1999/xhtml" ><br /><head runat="server"><br />    <title>LiveCycle Demo</title><br /><br />    <script language="javascript" type="text/javascript"><br />    <br />        function noenter() <br />        {<br />            // Returns False if enter key is pressed.<br />            return !(window.event && window.event.keyCode == 13); <br />        }<br />    <br />        function displayPDF()<br />        {<br />            var pdfContainer = document.getElementById("iframePDF");<br />            var myID = document.getElementById("myID").value;<br />            document.getElementById("myID").value = "";<br />            <br />            if ((myID == null) || (myID == ''))<br />            {<br />                // Display empty form.<br />                pdfContainer.src = "TestPage2.aspx";<br />            }<br />            else<br />            {<br />                // Display pre-populated form.<br />                pdfContainer.src = "TestPage2.aspx?id=" + pgaID;<br />            }<br />        }<br />    </script><br /><br /></head><br /><body><br />    <form id="form1" runat="server"><br />        <h2>Adobe LiveCycle PDF Demo</h2><br />        <button onclick="displayPDF()">Display PDF</button>   ID: <br />        <input id="myID" type="text" style="width: 48px" onkeypress="return noenter()" /><br />        <br /><br /><br />        <div st
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 11, 2007 9:32 AM   in reply to (YodaT)
    The html I supplied got mangled. If you are desperate, then view the source on this page an do a find on Default.aspx UI CODE.
     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2007 4:26 AM   in reply to (YodaT)
    Is there any shortcut way to show the PDF stored in Oracle database as BLOB in a web browser using ASP.NET? (VB not C#)?

    No involvement of XML and using data reader.
     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2007 11:45 PM   in reply to (YodaT)
    i want to create an pdf file using C# and xml/sfdf file?<br />how?<br /><br />Here I have an XML file:<br /><br /><?xml version="1.0" encoding="UTF-8"?><br /><xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><br /><f href="http://localhost/MyProject/sampleform.pdf"/><br /><fields><br /><field name="Name"><br />      <value>John</value><br /></field><br /><field name="Address"><br />      <value>95 Avenue Road</value><br /></field><br /></fields><br /></xfdf><br /><br />and i have code in C#:<br /><br />Response.Clear();               <br />               //Response.ContentType = "application/pdf";<br />               System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();               <br />               Response.AddHeader("Content-Header",xfdf.Length.ToSt ring());<br />               Response.AddHeader("Content-Disposition", "attachment;filename=form.pdf");<br />               Response.ContentType = "application/octet-stream";<br />               Response.BinaryWrite(ascii.GetBytes(xml));<br />==================<br /><br />but i don't know how to pass this xml to this code?<br />i want to generate a pdf file which contain as simple - Name: John Address: 95 Avenue Road like that... i will be greatful if you help in this matter, i am not getting any help related to xsdf tech on online. & how to pass this file to that code,so i can create that pdf file with the name.
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2007 4:44 AM   in reply to (YodaT)
    Hi,
    I have the following code to create the pdf file in the same browser

    Response.Clear()
    Response.ContentType = "application/x-pdf"
    Response.AddHeader("Content-Type", "application/x-pdf")

    Response.AddHeader("Content-Disposition", "attachment;filename=Record.pdf")
    Response.AddHeader("Content-Length", "Record")
    I am getting the file(Record.pdf) but only blank file not with the form text value
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2009 11:12 PM   in reply to (YodaT)

    Hi,

     

    For creating PDF documents on the server with data from a DB I suggest to use PDF Duo .Net converting component (download ASP.NET version of this component).

     

    It is easy to prepare the templates. Then take data from a DB and dinamicly create PDF files on the fly. For choise it is possible to save resulting PDF on the disk or show it in the browser wondow using next code(c#):

     

    1. conv.OpenHTML(htmlstring);
    2. conv.ShowPDF(conv.SavePDF(), Response);

     

    Nevertheless read the documentation of the PDF Duo .Net component.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 23, 2009 11:09 PM   in reply to (YodaT)

    I want to read a pdf file and extract only the required field like name, address,contact number etc from pdf file using ASP.NET With C#.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2011 8:19 PM   in reply to (YodaT)

    Check out FDFToolkit.net:

     

    FDFToolkit.net can read, populate, parse and merge PDF form field data FDF/XFDF/XML/XDP/XFA/PDF with Adobe Acrobat (Acroform) & LiveCycle (Static XFA) PDF Forms using Microsoft .NET programming languages, e.g: ASP.net, VB.net, C#.

     

    FDFToolkit.net works on workstations, servers, or both. Licenses are very flexible and inexpensive, built for developers by developers utlilizing iTextSharp technologies. Includes 1 year of technical support and updates w/ manual subscription renewals.

     

    For more information:

    http://www.fdftoolkit.net/

    http://www.nk-inc.com/software/fdftoolkit.net/examples/

    http://www.nk-inc.com/blog/

     

    Feel free to contact us:

    http://www.nk-inc.com/support/sales/

     

    Message was edited by: NKOWA

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 8:53 PM   in reply to (YodaT)

    1) Please try our product PDF-Writer.NET component designed to provide developers with an easy-to-use tool for creating standard PDF file from their .NET applications. The commands provided for adding content to documents are similar to the ones available in the .NET Graphics class. This makes it very easy to use and program

     

    2) Designed for Creating, Editing, Merge, Split, Fill Forms, Encryption, Digitial Sign, standard PDF file from .NET applications.

     

    3) Designed for WinForm , ASP.NET , WPF , Silverlight applications. . It is 100% managed and doesn't require any third-party DLLs.

     

    4) It includes 100% Source code.

     

    Please check below link for more info.

     

    http://www.dbautotrack.com/products/pdfwriter.html

     

    You can Download Full Version with implementation sample using the below link

     

    http://www.dbautotrack.com/downloads/index.html

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)