Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Using Adobe LiveCycle Designer with ASP.NET to populate PDF Forms from Server Database.

Avatar

Level 8

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Question:

With Google, I did a very very long search on how to use Adobe LiveCycle Designer to design Interactive/Dynamic Forms, and publish them to the IIS Server and use ASP.NET to populate such forms with field values from back-end Database such as SQL Server.



We are designing and implementing Electronic Forms ASP.NET Application that must detect the user currently logged in to the Windows Intranet (under IIS), and should perform a Look-up to the Back-End Database to extract the User Related Data and Populate the Form Fields to start the Form Processing.



We have the following facts:

1. The forms will be designed using Adobe LiveCycle Designer 7.1.



2. We will NOT use Adobe LiveCycle Forms since it is not on our budget yet.



3. The users will have the required Adobe Acrobat version on the Client PC.



In a typical scenario, the user would go through these steps:



1. The user logs on to the Intranet using his Windows Login ID and Password. Then he starts the APS.NET Application for Forms Processing.



2. He will request a form to fill. The form may be populated with sensitive information such as Salary and only the requesting user must be able to see his Salary on any form.



3. On the server side, the system will use the User Windows ID to perform a query against the Back-End Database and generate the required XML Data.



4. The system must then link/merge the generated XML Data with the requested form and render (post) the form back to the user for further printing and/or submitting via email.



That's it !



I found an add-in product "Adobe LiveCycle® Designer add-in for Microsoft Visual Studio .NET" but it only wraps XPD forms in Visual Studio Component which is not of a great help to my requirements.



If any one could give me any hint on how to implement such requirements.



I truly appreciate any help.



Tarek.

275 Replies

Avatar

Former Community Member

Hello Tarek,

Hope you are doing well.

I have an issue to share with related to this thread...

I manage to submit pdf form to asp.net page and read whole chunk to binaray data, but some times i got exception when write this binary data to pdf file.

this issue occured to me once a while only let say less than 1%, but in production that causing me more problem. can you please give an idea.

chunk = xmldoc.GetElementsByTagName("chunk")(0).InnerXml

Dim buffer() As Byte = Convert.FromBase64String(chunk)

Dim fs AsSystem.IO.FileStream = New System.IO.FileStream(Server.MapPath("XYZ.pdf"), IO.FileMode.Create, FileAccess.ReadWrite)
Dim bw As System.IO.BinaryWriter = New System.IO.BinaryWriter(fs)
bw.Write(buffer)
bw.Close()
bw = Nothing
fs.Close()
fs = Nothing

Thank you.

Avatar

Level 8

Hi Aravind,

What is the error you are getting? Out of Memory Exception?

Please post the complete error and stack trace.

Also, check this thread, I also faced this error, and found a resolution to some extent:

http://forums.asp.net/t/1662571.aspx/1?URGENT+Exception+OutOfMemoryException+thrown+when+when+conver...

Let me know if this is similar to your problem, I will updated the source code on my Google Workspace to the latest version, OK?

Tarek.

Avatar

Level 2

HI Tarek,

I have implemented the feature to display a fillable PDF in the browser within an iFrame, allow the user to fill the form fields and then save the changes by using a Save button in the PDF document.

Clicking Save button within the PDF document will trigger HTTPSUBMIT and submits the entire PDF document to the application server from where I'm pushing the PDF to the database.

Now, instead of having the save button within the PDF document, I would like to have it outside the PDF (i.e. directly in the web page). Can this be achieved? I tried different things but couldn't find solution.

Avatar

Level 8

Hi Anand,

Yes, I think it is possible, with some extra programming effort.

I never done this before, and I like to do it one day.

You need to use the HostContainer Object to pass messages between the browser and the PDF.

Check this online demo:

http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm

Let me know if it works.

Tarek.

Avatar

Level 1

Hello Tarek,

I'm new to Adobe Acrobat/LiveCycle and wanted to ask for your adice on how to establish the following process:

1. Create a PDF form template using Adobe LiveCycle ES.

2. Using ASP.NET application bind this template with fields from MS SQL Server

3. Save PDF result in database as a binary object (VARCHAR(MAX))

4. Send PDF to a client's browser

I was trying to use Acrobat SDK for static forms (FillFormCS) using XML data biding but I'm wondering if there's a better solution available to render PDF in .NET object, save it as a stream and send it back to the client. FillFormCS requires to save a PDF template with a new name on local disk first before binding form data.

Thank you in advance!

Boris

Avatar

Level 8

Hi Boris,

I will answer your questions accordingly:

1. Open Adobe LiveCycle Desinger and take menu option File/New, select "Based on a Template" and follow the Wizard. You will find large number of ready templates that will be a great start for you.

2. Check this public folder on Google Docs: http://adobe.ly/GX7LR3 . It has a guide and bunch of file to help you get started. Let me know of you have any trouble understanding its content. Look for this document "Developer Guide: How to use ASP.NET to work with LiveCycle PDF Forms and Data"

3. You can save the entire PDF as Binary in a SQL Server Field varbinary(max) not varchar(max). But, I recommend you not to do so. You should store the PDF as a File on a File System it is much better. My sample code shows you how to save the submitted PDF as XML Text File and also as PDF Binary File. Trust me on this, and do not store the PDF inside a SQL Server field.

Also, you can store XML Elements Data (Form Field Values) to designated SQL Server Fields. My sample code shows you exactly how to do that.

4. My sample code also shows you how to retreive the PDF Binary from File System and also, as per certain conditions, retrieve data from SQL, merge it with PDF (empty template), and finaly send the result to the client.

With regards to using Acrobat SDK, it is simply another option. But certainly this is for Desktop Applications not for Web Applications (I think). You will also find another sample in the above link for an entire working project for this purpose, and it think it will blow you mind away

Let me know if you need further help.

Tarek.

Avatar

Level 1

Thank you, Tarek, for your quick response!

The following link http://adobe.ly/GX7LR3 points to the current adobe forum discussion rather than public folder on Google Docs.

Please advise.

Thanks,

Boris

Avatar

Level 1

WOW... This folder has a lot of examples. Thank you VERY much, Tarek!

I've noticed that many examples are written in VB.NET. By any chance, do you have some examples using C#?

Thank you again!

Boris

Avatar

Level 8

Thanks Boris,

So far, only in VB.NET. If you can convert some of the example to C# that would be excellent.

Tarek.

Avatar

Level 2

I was finally able to achieve this after weeks of research and programming...I used HostContainer object to pass message between the browser (ASP.NET web form) and the PDF. Have created a document level javascript in the PDF to accept the message and handle it to either submit the form to the server, show print dialog or show saveas dialog box.

I have removed the Save, Print, and Download buttons from my form and added them to the main web form.

Regards,

Anand

Avatar

Level 8

Hi Anand,

This is great ! I was also dreaming to implement this using HostContainer. Did you follow the code from this example:

http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm

I would be great if you could post samples of your work, especially the JavaScript code in the Browser and in the PDF.

Tarek.

Avatar

Level 2

Yes, I referred the code sample in that link.

Below is the document level javascript to be added to the PDF to handle Save, Print and Download messages from the browser,

this.disclosed = true;

if(this.external && this.hostContainer)

{

  function onMessageFunc( stringArray )

  {

    var myUrl = stringArray;

try{

if (myUrl == "print")

{

// get the printParams object of the default printer

var pp = this.myDoc.getPrintParams();

// set some properties

pp.interactive = pp.constants.interactionLevel.full;

// print

this.myDoc.print(pp);

}

else if (myUrl == "download")

{

app.execMenuItem("SaveAs", this.myDoc);

}

else

{

this.myDoc.submitForm({

cURL: myUrl,

cSubmitAs: "PDF"});

}

}

catch(e){app.alert(e.message);}

  }

  function onErrorFunc( e )

  {

app.alert(e.toString());

  }

 

  try

  {

     if(!this.hostContainer.messageHandler)

       this.hostContainer.messageHandler = new Object();

 

     this.hostContainer.messageHandler.myDoc = this;

     this.hostContainer.messageHandler.onMessage = onMessageFunc;

     this.hostContainer.messageHandler.onError = onErrorFunc;

     this.hostContainer.messageHandler.onDisclose = function(){return true;};

//HostContainerDisclosurePolicy.SameOriginPolicy;

//app.alert("Browser Message Handlers setup");

   

  }catch(e){app.alert(e.toString());};

 

}

Below is the javascript in my ASPX page to pass message to the PDF once the button in the web page is clicked,

<script type="text/javascript">

        function Button2_onclick() {

            var PDFObject = document.getElementById("PdfObject");

            if (PDFObject != null) {

                //alert("PDF object found!!");

                PDFObject.postMessage(["http://localhost/PdfProcessor.aspx?SubmittedFormPart=1"]);

            }

        }

        function Print_onclick() {

            var PDFObject = document.getElementById("PdfObject");

            if (PDFObject != null) {

                //alert("PDF object found!!");

                PDFObject.postMessage(["print"]);

            }

        }

        function Download_onclick() {

            var PDFObject = document.getElementById("PdfObject");

            if (PDFObject != null) {

                //alert("PDF object found!!");

                PDFObject.postMessage(["download"]);

            }

        }

    </script>

Below is the ASPX code to bind the PDF via HTTP handler to the <Object>

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

    CodeBehind="Default.aspx.cs" Inherits="SaveOutsidePdf._Default" %>

    <script runat="server">

    private string _PdfPath;

    protected void Page_Load(object sender, EventArgs e)

    {

        _PdfPath = "StaticPdfHandler.ashx#toolbar=0&navpanes=0";

    }

</script>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <input id="SaveFilledPdf" type="button" value="Save PDF"

        name="SaveFilledPdf" language="javascript" onclick="return Button2_onclick()">

      <input id="PrintButton" type="button" value="Print PDF"

        name="PrintPdf" language="javascript" onclick="return Print_onclick()">

          <input id="DownloadFilledPdf" type="button" value="Download PDF"

        name="DownloadFilledPdf" language="javascript" onclick="return Download_onclick()">

    <object id="PdfObject" data='<%=_PdfPath %>' width="100%" height="600px"

    type="application/pdf"></object>

</asp:Content>

Let me know if you have any questions.

Avatar

Level 8

Thank you Anand,

This is wonderful !

Do you mind if I add you code sample to my documentation on Google Docs which is public? Of course, I will refernce you name.

Tarek.

Avatar

Former Community Member
Hello, I need a group with an image jpg and to be able to call and to fill up this group from asp, a greeting

Avatar

Level 8
Dear All,



I was able to submit the PDF from the Client to Server (URL) and handle the submission using ASP.NET Program.



I was able to extract data and PDF from the chunk element successfully and write it as binary to PDF file on the server.



I was also able to merger data with PDF using XML and write the response back to the client as XDP ....



Everything works perfectly now.



I have one small problem.



On some client PCs, when the XDP is rendered back to the client browser, sometimes I get a Prompt asking the user to save or open the XDP file, and on other users PC, it is opening the XDP as PDF immediately.



How I can control such setting ? From where exactly ?



Regards ...



Tarek.

Avatar

Former Community Member
Tarek can you explain how you are able to submit a pdf form as a pdf (write as a binary file on the server) via ASP.NET? I do not need to write the form values to a database rather I would like to keep the pdf form as is.



Thanks

Mehmet

Avatar

Level 8
Dear Mehmet,



Sure I am glad to help. I will give you quick answer now, and on Sat I will give complete sample code.



On the form, submit button, mouse up event, use Acrobat JavaScript: event.target.submitForm and include the parameters to submit the entire pdf to URL (ASP.NET Program).



In asp.net, use the request object to retrieve the binary data and use binary writer to write to an file .pdf.



When I am back in the office on Saturday, I will give COMPLETE sample code. In case I forget, please send me a reminder ok?



Tarek.

Avatar

Former Community Member
Dear Tarek,



I also need your sample code, as I am also working on adobe livecycle now, but i am haven't any idea about this.



If you can send me some sample code about LiveCycle form with ASP.NET and SQL Server, it is great appreciated.



Thanks!

Stanley