Expand my Community achievements bar.

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
Try this<br />/Ulf<br /> Response.ContentType = "application/vnd.adobe.xdp+xml" <br /> responseString.Append("<?xml version='1.0' encoding='UTF-8'?>") <br /><br /> responseString.Append("<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>") <br /> responseString.Append("<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>") <br /> responseString.Append("<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>") <br /> responseString.Append("<xfa:data>") <br /><br /> responseString.Append("<form1>") <br /> responseString.Append("<txtFirstName>Homer</txtFirstName>") <br /> responseString.Append("<txtLastName>Simpson</txtLastName>") <br /> responseString.Append("</form1>") <br /><br /> responseString.Append("</xfa:data>") <br /> responseString.Append("</xfa:datasets>") <br /> responseString.Append("<pdf href='http://localhost/PDFFiller/TestForm.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />") <br /> responseString.Append("</xdp:xdp>") <br /><br /> Response.Write(responseString) <br /> Response.Flush() <br /> Response.End()

Avatar

Level 8
Dear All,<br /><br />Please find below the sameple code to create the Leave Form PDF and merge it with data from back-end database, enjoy:<br />****************************<br />Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br /> Dim CurrUserInfo As New [Class].Employee<br /> Dim LeaveTotals As New [Class].Leave<br /> Dim strXML As String<br /> Dim LeaveBalUpdatedOn As String<br /> 'Response.Write("User ID = " & Session("CurrUserTXT") & "<br>")<br /> 'Response.Write("Name = " & Session("CurrUserInfo") & "<br>")<br /> 'Response.Write("Logon User = " & Request.ServerVariables("LOGON_USER") & "<br>")<br /> 'Replace the code below to retreive info from back-end with you own code.<br /> CurrUserInfo = [Class].Employee.ShowEmployeeDetails(Session("CurrUser")) 'Session("CurrUserInfo")<br /> LeaveTotals = [Class].Leave.GetTotal(CType(Session("CurrUserTXT"), String))<br /> '<br /> ' Set Content Type for using XDP<br /> '<br /> Response.ContentType = "application/vnd.adobe.xdp+xml"<br /> '<br /> ' Constant XDP Header<br /> '<br /> strXML = "<?xml version='1.0' encoding='UTF-8'?>"<br /> strXML = strXML & "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>"<br /> strXML = strXML & "<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>"<br /> strXML = strXML & "<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>"<br /> strXML = strXML & "<xfa:data>"<br /> '<br /> ' Place code here to get the current Logged in user ID<br /> ' and perfrom a query to the back end database and filter by ID<br /> ' then generate the following XML Data using the resultant Recordset ...etc.<br /> '<br /> strXML = strXML & "<topmostSubform>"<br /> strXML = strXML & "<LeaveSec1>"<br /> strXML = strXML & "<Name>" & Session("CurrUserInfo") & "</Name>"<br /> strXML = strXML & "<StaffID>" & Session("CurrUserTXT") & "</StaffID>"<br /> strXML = strXML & "<Dept>" & Server.HtmlEncode(CurrUserInfo.FldPositionNo) & "</Dept>"<br /> strXML = strXML & "<JobTitle>" & Server.HtmlEncode(CurrUserInfo.FldOccupationName) & "</JobTitle>"<br /> strXML = strXML & "</LeaveSec1>"<br /> strXML = strXML & "<LeaveSec4>"<br /> strXML = strXML & "<LeaveBalance>" & Server.HtmlEncode(LeaveTotals.AnnualLeaveBalance) & "</LeaveBalance>"<br /> LeaveBalUpdatedOn = LeaveTotals.BalanceUpdatedOnHijri & " H (" & LeaveTotals.BalanceUpdatedOnGreg & " G)"<br /> strXML = strXML & "<BalanceUpdatedOnHijri>" & Server.HtmlEncode(LeaveBalUpdatedOn) & "</BalanceUpdatedOnHijri>"<br /> strXML = strXML & "</LeaveSec4>"<br /> strXML = strXML & "</topmostSubform>"<br /> '<br /> '<br /> '<br /> strXML = strXML & "</xfa:data>"<br /> strXML = strXML & "</xfa:datasets>"<br /> '<br /> ' Point the XPD to the PDF Form created under Adobe LiveCycle Desinger<br /> '<br /> strXML = strXML & "<pdf href='http://idbnet/eHRMDDev/LeaveForm-tst.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />"<br /> '<br /> ' Close the XPD File<br /> '<br /> strXML = strXML & "</xdp:xdp>"<br /> Response.Write(strXML)<br /> Response.Flush()<br /> Response.End()<br /> End Sub

Avatar

Level 8
Use the JavaScript code sample below in PDF Button, MouseUp or Click Event, to submit the PDF to the ASP.NET Page:



***************

//debugger

var address = LeaveSec1.ContactAddressLeave.rawValue;

var replacingStaff = LeaveSec1.ReplacingStaff.rawValue;

var mySignature = event.target.getField("topmostSubform[0].LeaveFormPage[0].LeaveSec1[0].SignatureStaff[0]");

//var mySignature = xfa.resolveNode("topmostSubform.LeaveFormPage.SignatureStaff");

if (mySignature.signatureValidate() <= 0) {

app.alert("Please sign the form before submitting to your Supervisor !");

} else

if (address == "" || address == null || replacingStaff == "" || replacingStaff == null) {

app.alert("Please enter value for Address and Replacing Staff before submitting to your Supervisor !");

xfa.host.resetData(mySignature);

} else

{

event.target.submitForm(

{cURL: "http://blablabla/LeaveProcess.aspx?SubmittedFormPart=1",

aPackets:["datasets","pdf"], cSubmitAs: "XDP"});

}

Avatar

Level 8
Find Below a complete sample code to process the submitted Leave Form with Email/Workflow sort of features.



I hope you will like it.



----------------------



Const CompanyDomain As String = "xxx.org"

Const CompanyEmailSuffix As String = "@" & CompanyDomain

Const TechSupportEmail As String = "TechSupport" & CompanyEmailSuffix



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim fs As System.IO.FileStream = Nothing

Dim bw As System.IO.BinaryWriter = Nothing

Dim ArchivingDBConn As New System.Data.OleDb.OleDbConnection

Dim ArchivingDBCmd As New System.Data.OleDb.OleDbCommand

Try

Dim ServerPath As String = Server.MapPath(".")

Dim LeaveFormFileName As String

Dim LeaveFormFileNameFolder As String

Dim fso As New Scripting.FileSystemObject

Const CONeForms As String = "eForms"

Dim eFormsFolder As String = ServerPath & "\" & CONeForms & "\" & Session.SessionID

If Not fso.FolderExists(eFormsFolder) Then

fso.CreateFolder(eFormsFolder)

End If

Dim sreader As New System.IO.StreamReader(Page.Request.InputStream)

Dim xmlData As String = sreader.ReadToEnd()

Dim xmldoc As New System.Xml.XmlDataDocument

Dim chunk As String

Dim buffer() As Byte

Dim SubmittedFormPart As String

Dim SendFormToEmail As String, SendFormFromEmail As String



xmldoc.LoadXml(xmlData)

Session("SubmittedFormPart") = Request.QueryString("SubmittedFormPart")

SubmittedFormPart = Session("SubmittedFormPart").ToString

Session("StaffName") = xmldoc.GetElementsByTagName("Name")(0).InnerText

Session("StaffID") = xmldoc.GetElementsByTagName("StaffID")(0).InnerText

Session("StaffEmail") = Session("StaffID") & CompanyEmailSuffix

'Session("SubmittedFormSection") = xmldoc.GetElementsByTagName("SubmittedFormSection")(0).InnerText

Session("EmailSupervisor") = xmldoc.GetElementsByTagName("emailSupervisor")(0).InnerText

Session("EmailDeptHead") = xmldoc.GetElementsByTagName("emailDeptHead")(0).InnerText

Session("EmailHRMD") = xmldoc.GetElementsByTagName("emailHRMD")(0).InnerText

Session("EmailEDocFlow") = xmldoc.GetElementsByTagName("emailEDocFlow")(0).InnerText

Session("LeaveStartDate") = xmldoc.GetElementsByTagName("LeaveStartDate")(0).InnerText

Session("AdvanceLeave") = xmldoc.GetElementsByTagName("AdvanceLeave")(0).InnerText

Session("HRMDApproved") = xmldoc.GetElementsByTagName("HRMDApproved")(0).InnerText

Session("emailFinance") = xmldoc.GetElementsByTagName("emailFinance")(0).InnerText

If Session("LeaveStartDate") = "" Then

Session("LeaveStartDate") = Date.Today.ToString("yyyy-MM-dd")

Else

Dim arrChar() As Char = Session("LeaveStartDate").ToString.ToCharArray

Dim c As Char, strLeaveStartDate As String = ""

For Each c In arrChar

strLeaveStartDate = strLeaveStartDate & Chr(Asc(c))

Next

'Session("LeaveStartDate") = Convert.ToDateTime(strLeaveStartDate).ToString("yyyy-MM-dd")

Session("LeaveStartDate") = Date.Parse(strLeaveStartDate, New System.Globalization.CultureInfo("en-GB")).ToString("yyyy-MM-dd")

End If

If Session("StaffID") = "" Then

Response.Write("

ERROR: Staff ID was not specified. Please try again.

")

Response.End()

End If

LeaveFormFileName = "Leave-" & Session("StaffID") & "-" & Session("LeaveStartDate") & ".pdf"

LeaveFormFileNameFolder = eFormsFolder & "\" & LeaveFormFileName



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

buffer = Convert.FromBase64String(chunk)

If fso.FileExists(LeaveFormFileName) Then

fso.DeleteFile(LeaveFormFileName, True)

End If

fs = New System.IO.FileStream(LeaveFormFileNameFolder, IO.FileMode.Create)

bw = New System.IO.BinaryWriter(fs)

bw.Write(buffer)

bw.Close()

bw = Nothing

fs.Close()

fs = Nothing

Dim LeaveFormLink As String = "./" & CONeForms & "/" & Session.SessionID & "/" & LeaveFormFileName

Dim BaseLink As String = Request.Url.GetLeftPart(UriPartial.Authority)

Dim thisWebRoot As String = Request.Path

If Left(thisWebRoot, 1) = "/" Then

thisWebRoot = thisWebRoot.Substring(1)

End If

Dim j As Integer = thisWebRoot.IndexOf("/")

thisWebRoot = thisWebRoot.Substring(0, j)

BaseLink = BaseLink & "/" & thisWebRoot

Dim LeaveFormLinkAbsolute As String = BaseLink & "/" & CONeForms & "/" & Session.SessionID & "/" & LeaveFormFileName

Dim LeaveFormHTMLLink As String = "
Click her to open the Leave Form (Temporary File) '" & LeaveFormFileName & "'"

Dim LeaveFormHTMLLinkAbsolute As String = "
Click her to open the Leave Form (Temporary File) '" & LeaveFormFileName & "'"

Dim EmailSubject As String = "", EmailBody As String = ""

Dim FormProcessingType As String = "", ArchivingRefNo As String = "(not ready yet)"

Dim qArchivingLastRefNo As System.Data.OleDb.OleDbDataReader

Dim ArchivingFolder As String = "E:\AppShares\eForms\HRMD"

Dim ArchivingFolderPDF As String = ArchivingFolder & "\" & LeaveFormFileName

Dim ArchivingLinkPDFAbsolute As String = "http://blablabla/eForms/HRMD/" & LeaveFormFileName

Dim ArchivingLinkPDFHTMLAbsolute As String = "
Click her to open the Archived Leave Form File '" & LeaveFormFileName & "'"

Select Case SubmittedFormPart

Case "1"

SendFormToEmail = Session("EmailSupervisor")

SendFormFromEmail = Session("StaffEmail")

FormProcessingType = "Leave Form Initiated by Staff, pending Supervisor Approval"

Case "2"

SendFormToEmail = Session("EmailDeptHead")

SendFormFromEmail = Session("EmailSupervisor")

FormProcessingType = "Leave Form Approved by Supervisor, pending Director Approval"

Case "3"

SendFormToEmail = Session("EmailHRMD")

SendFormFromEmail = Session("EmailDeptHead")

If SendFormFromEmail = "" Then

SendFormFromEmail = Session("EmailSupervisor")

End If

FormProcessingType = "Leave Form Approved by Director, pending HRMD Approval"

Case "4"

SendFormFromEmail = Session("EmailHRMD")

If Session("HRMDApproved") = "1" Then

SendFormToEmail = Session("EmailEDocFlow")

FormProcessingType = "Leave Form Approved by HRMD, pending Final Processing"

If Session("AdvanceLeave") = "1" Then

SendFormToEmail = SendFormToEmail & "," & Session("emailFinance")

End If

Else ' REJECTED

SendFormToEmail = Session("StaffEmail")

FormProcessingType = "Leave Form Rejected by HRMD"

End If

Case Else

SendFormToEmail = TechSup

Avatar

Level 8
'''continuation'''



Case Else

SendFormToEmail = TechSupportEmail

SendFormFromEmail = Session("StaffEmail")

FormProcessingType = "Error in Submitted Form Part = '" & SubmittedFormPart & "'"

End Select

Dim myEmail As New System.Net.Mail.MailMessage(SendFormFromEmail, SendFormToEmail)

myEmail.IsBodyHtml = True

EmailBody = "



" & FormProcessingType & "






"

If SubmittedFormPart >= "1" And SubmittedFormPart <= "3" Then

EmailSubject = "Leave form of '" & Session("StaffName") & "' pending your approval."

EmailBody &= "

The Leave Form of
'" & Session("StaffName") & "' was submitted for your kind approval.


Please click on the link below to open and form, sign it and submit it for further approval.

"

EmailBody &= "

" & LeaveFormHTMLLinkAbsolute & "

"

ElseIf SubmittedFormPart = "4" Then



If Session("HRMDApproved") = "1" Then

'

' APPROVED

'

If fso.FileExists(ArchivingFolderPDF) Then

fso.DeleteFile(ArchivingFolderPDF)

End If

fso.CopyFile(LeaveFormFileNameFolder, ArchivingFolderPDF)



ArchivingDBConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\AppShares\eForms\HRMD\DB\Index_MasterFiles.mdb"

ArchivingDBConn.Open()

ArchivingDBCmd.Connection = ArchivingDBConn

ArchivingDBCmd.CommandType = Data.CommandType.StoredProcedure

ArchivingDBCmd.CommandText = "qArchivingLastRefNo"

qArchivingLastRefNo = ArchivingDBCmd.ExecuteReader()

If qArchivingLastRefNo.HasRows Then

qArchivingLastRefNo.Read()

If Not qArchivingLastRefNo.Item("LastRefNo").Equals(System.DBNull.Value) Then

ArchivingRefNo = (qArchivingLastRefNo.Item("LastRefNo") + 1).ToString

Else

ArchivingRefNo = "1"

End If

Else

ArchivingRefNo = "1"

End If

qArchivingLastRefNo.Close()

ArchivingDBCmd.CommandType = Data.CommandType.Text

ArchivingDBCmd.CommandText = "insert into [KOFAX-File] ([Field1], [IncominG]) values ('" & ArchivingRefNo & "',1)"

If ArchivingDBCmd.ExecuteNonQuery() <= 0 Then

Throw New Exception("Unexpected error: Zero records inserted into table [KOFAX-File].")

End If

ArchivingDBCmd.CommandText = "insert into [OMDMasterFiles] ([DocId], [DocId1], [Image]) values ('" & ArchivingRefNo & "', " & ArchivingRefNo & ", '" & ArchivingLinkPDFAbsolute & "')"

If ArchivingDBCmd.ExecuteNonQuery() <= 0 Then

Throw New Exception("Unexpected error: Zero records inserted into table [OMDMasterFiles].")

End If

ArchivingDBCmd.Dispose()

ArchivingDBConn.Close()

ArchivingDBCmd = Nothing

ArchivingDBConn = Nothing



EmailSubject = "Leave form of '" & Session("StaffName") & "' pending final processing and archiving."

EmailBody &= "

The Leave Form of
'" & Session("StaffName") & "' is pending final processing, archiving and linking to eDocFlow under Lotus Notes.

"

EmailBody &= "

The Archiving Ref. No. to link this Form to Lotus Notes eDocFlow is: " & ArchivingRefNo & ".

"

EmailBody &= "

" & ArchivingLinkPDFHTMLAbsolute & "

"

Else ' REJECTED

EmailSubject = "Leave form of '" & Session("StaffName") & "' Rejected by HRMD."

EmailBody &= "

The Leave Form of
'" & Session("StaffName") & "' was Rejected by HRMD.

"

EmailBody &= "

Please click on the link below to open the form, revise the fields and submit again if needed.

"

EmailBody &= "

" & LeaveFormHTMLLinkAbsolute & "

"

End If

Else

EmailSubject = "*** ERROR **** Unexpected value for SubmittedFormPart = '" & SubmittedFormPart & "'"

EmailBody &= "

Please report this error to technical support

"

EmailBody &= "

Leave Form for
'" & Session("StaffName") & "'

"

EmailBody &= "

" & LeaveFormHTMLLinkAbsolute & "

"

End If

myEmail.Subject = EmailSubject

myEmail.Body = EmailBody

Dim smtpc As New System.Net.Mail.SmtpClient("put.your.smpt.ip.address.here")

smtpc.Send(myEmail)

Response.Write("Leave Form For:
" & Session("StaffName") & "

")

Response.Write("

The Submitted Form Part: " & Session("SubmittedFormPart") & "

")

Response.Write("

The Submitted Form Status: " & FormProcessingType & "

")

Response.Write("

Eamil was sent from '" & SendFormFromEmail & "' to '" & SendFormToEmail & "'

")

If SubmittedFormPart = "4" Then

If Session("HRMDApproved") = "1" Then

Response.Write("

The leave form was Approved and Archived Successfully.

")

Response.Write("

" & ArchivingLinkPDFHTMLAbsolute)

Else

Response.Write("

The leave form Rejected by HRMD and returnd to Staff.

")

Response.Write("

" & LeaveFormHTMLLink)

End If

Else

Response.Write("

The Leave Form was Submitted and a new Temporary PDF File was created Successfully !

")

Response.Write("

" & LeaveFormHTMLLink)

End If

Response.Write("

You can add the above link to your Favorites so that you can refer to it later !

")

xmldoc = Nothing

Catch ex As Exception

Dim err As String = "

Error Occured while submitting the leave form. See details below.



" & _

"Error in: " & Request.Url.ToString() & _

"



" & _

"Error Message: " & ex.Message.ToString() & _

"



" & _

"Stack Trace:" & ex.StackTrace.ToString() & _

"



Please report to Technical Support.

"

Response.Write(err)

Finally

If Not bw Is Nothing Then

bw.Close()

End If

If Not fs Is Nothing Then

fs.Close()

End If

If Not ArchivingDBCmd Is Nothing Then

ArchivingDBCmd.Dispose()

End If

If Not ArchivingDBConn Is Nothing Then

ArchivingDBConn.Close()

End If

End Try



End Sub

Avatar

Level 8
Ref. to the posted code above, I do not know what happened as it was messed up after I posted it. You will spend some effort to find the code you want.



Good luck.



Tarek.

Avatar

Former Community Member
Dear Ulf,



Thanks a lot for your help.



I have some idea on my work.



Thanks!



Best Regards,

Stanley

Avatar

Former Community Member
Dear Tarek,



oh great! Thanks a lot for your code.

It's really save much time for me.



Thanks again!



Best Regards,

Stanley

Avatar

Level 8
Mr. Stanley,



Do I know you ? I have a colleague who has same name, or is it just a co-incidence ?!



Regards ...



Tarek.

Avatar

Former Community Member
Displaying & Submitting "Interactive PDF Forms".



1) User browses to page on website.

2) Page displays an interactive pdf form

3) User fills out the fields in the form

4) User click the "submit" button, the interactive pdf form is flattened and saved to a folder on the webserver. Or, the flattened pdf is emailed to other users.



I can easily create the interactive pdf using Adobe Professional, but how can I display the pdf and capture the "submitted" flattened pdf?

Avatar

Level 8
Kyle Parker,



If I understand your question correctly, you want to display the PDF on the Client Browser, and the user will fill in the form, then submit to a server. On the server, you need to capture the field value, right ?



Please go back to the beginning of this form, and the sample code I provided does both parts:



1. Use APS.NET to read field values from Database and merge it with Adobe LiveCycle Form (not Acrobat Form). If you are using Acrobat Forms, I guess you have to convert it.



2. In the PDF, there is Java Client Script to Submit the form to a Server.



3. When the form is submitted, there is a sample code that shows you how to retrieve the XDP Package, and parse it to extract the field values. The code was messed up, but if you copy/past to Notepad, it should look better, and you need to spend some effort to get the parts you need.



The program is working fine here at work since it was deployed, and it was a revolution in my company. I think I was the first person to use Adobe PDF in such manner from A to Z.

Avatar

Former Community Member
Hi Tarek

I have the same requirement to show data in pdf,. I am able to fill the textboxes, but i am not able to set the values of checkbox and radio buttons.. :(

i tried by setting the value like 1,'yes','checked','on', but nothing works for me..

do you have any idea? or anyone else have any idea about that?

Avatar

Level 8
gagankhurana,



I will teach a good trick to solve related problems, but this is a secret ! (just kidding).



1. Create the Form in Adobe LiveCycle Designer,



2. Open the PDF in Adobe Acrobat,



3. Fill the Form Fields with all the kind of values you need,



4. Use the Form Menu option to Export the Values to CSV or XML,



5. Open the exported XML/CSV/Text file and examine the field Names and Values. This is useful for programming in JavaScript also,



6. To confirm, change the field values as you like and save the XML/CSV/Text,



7. Go back to Adobe Acrobat, and Import the new file to the form,



8. Enjoy ...



Tarek.

Avatar

Former Community Member
Thanks Tarek..

I got it..

This SECRET tip is great in itself...:)

I will keep in mind.

I tried and everything is working now...

Thanks again Tarek.

Avatar

Former Community Member
Tarek, or anyone for that matter help would be great.



I have a vital form that clients fill out, which is passed to many people in the company along the workflow. The form is a Planner and we have in the following PDF, Word Doc..



Well before, the Planner.pdf was originally created in Word, since most people have access to Word.. but evolved to a PDF form created from the Word Doc via Adobe LiveCycle Designer 8.0 w/ User Rights enabled so that the form could be filled out and saved using Adobe Reader.. which was a step better than Word.. being that it is free. But this needed to be easier and more to the point b/c some clients don't particularly like installing the latest version of Reader, even if you provide them the link. Nor do they like saving the form, filling the form, and attaching the form to send back.



My goal is to have the client fill an HTML version of the form, submit and be done with it, but everyone in the workflow be able to easily receive the filled Planner as a PDF form.



So some months ago I ran into this post
Chris Trip, "Populate Livecycle PDF from mySQL database using PHP" #8, 22 Sep 2007 4:37 pm



which uses the command line Win32 pdftk.exe to merge an FDF file into an existing PDF on the remote server, and serve this to whoever.



My problem was with shared hosting and having the ability to use the Win32 pdftk.exe along with PHP which is predominantly used on Linux boxes. And we used a Linux box.



so i created the following unorthodox method, which a client fills the HTML version of the Planner, all field values are INSERTED into a table in MySQL DB, I and all filled planners that have been filled by clients to date can be viewed from a repository page where an XML file is served up of the corresponding client, but someone would have to have Acrobat Professional, to import the form data from the XML file into a blank form.. altoughh this is simple for me.. I have the PHP file already created so that when a Planner is filled and client submits. >> the an email is sent to me with a table row from the repository of the client name, #, email, and a link to d-load the XML file,



But I also have the PHP files created so that the Planner can be sent to by email to various people in the workflow with certain fileds ommitted they they do not need to see, but instead of the XML file beiong served up i need the filled PDF Planner to be served.



I can do this locally with ease on a testing server, but I am currently trying to use another host that uses cross-platform compatibility so i can use PHP and the pdftk.exe to achieve this, as that is why I am having to serve up an XML file b/c we use a Linux server for our website, and cant execute the exe.



Now that I am testing the other server (cross-platform host), just to use them to do the PDF handling (and it's only $5 per month) I am having problems with getting READ, WRITE, EXECUTE permissions..



Si guess a good question to ask is can PHP do the same procedure as the pdftk.exe, and i can eleminate it.



or how in the heck can i get this data from the DB into a blank PDF form, like i have described??



here are some link to reference



Populating a LiveCycle PDF with PHP and MySQL

http://www.andrewheiss.com/Tutorials?page=LiveCycle_PDFs_and_MySQL



HTML form that passed data into a PDF

http://www.mactech.com/articles/mactech/Vol.20/20.11/FillOnlinePDFFormsUsingHTML/index.html

and an example

http://accesspdf.com/html_pdf_form/



Well some months

Avatar

Level 8
Dear Chris,



First of all, I like to thank you for letting me know about Win32 pdftk.exe tool. I think I might use it one day.



I am not sure if I follow you 100%... you have provided a lot of details and so many variable ... I am a little bit lost !



I have read you post several time, and I will give you my feedback to the best of my understanding, and hope that it will make sense to you.



First of all we have to agree of some constant parameters with regards to our problem:



1. We are using Adobe LiveCycle Technology, not Acrobat. I am sure you know the difference.



2. We will use Adobe PDF for Form Data Entry, Submission to the Server, and Form Rendering from the server to the Client by merging data from Back-End Database with the form.



3. The client users must have Adobe Reader to be able to work with the form, and the form can be Reader-Enabled which is a plus (or a must depending on what features you need to use). If some clients do not want to install Adobe Reader, then your solution must be smarter and must adopt some tools to convert PDF to HTML on the Server and push back the result to the client. I did not use such solution, and I know some Adobe Server Products have such feature.



4. I do not know PHP. I use ASP.NET, but I am sure you should be able to find the equivalent in PHP, and I will give you concepts, not language specific details. (Note: at our work environment, we have a farm of different different technologies and platforms and tools, and I am really lost ! My colleague knows PHP and MySQL).



Your Requirement:

=================

You want to use PHP to simulate the work of Win32 pdftk.EXE. Correct ?



Solution:

=========

Keeping in mind the parameters mentioned above, here is what you need to do:



1. Form Data Entry and Submission to the Server: Design the Form in LiveCycle and create a Button with the needed JavaScript to submit the form to the server and pass the entire Form Data Fields as XML and the PDF Form as Binary, as needed. Check the sample code in this thread in an earlier post. Use : event.target.submitForm(...).



If Adobe Reader is installed and configured properly on the client, then a simple URL Link to the form on the server will do the job. I think the form must be Reader Enabled in order to make some feature work, but I cannot remember all the details.



2. Processing the Form on the Server: the client JavaScript command: event.target.submitForm(...) will do the required magic, after that it is all Web Standards. On the server, you Server-Side Script must use the Request Object to receive the Form Fields and PDF Form File in XML Document and with simple Parsing and Data Conversion, you job is done. I have done this using ASP.NET Server Side Objects and Tools. I am almost 100% sure you will find something similar in PHP. Check the sample code I provided earlier for details.



The received XML Document has 2 major parts: Form Data and PDF File in a String Representation of the Binary Format. This was a tricky part, but I managed to use it to re-create the PDF on the server AS-IS with the help of the Engineer form a Local Adobe Support Representative.



3. Form rendering by Merging the Form Fields with Data from the Back-End Database: Develop a Server-Side Program to do this part using PHP. You simple need to write the code to connect to the Database, open the required Table/View/Stored Procedure ....etc.. and put the required Fields in Server Side Variables. I usually use Session Variables, just in case I need to split my code among several server-side ASPX web pages. Then, you need to have one LONG String Variable to construct the XDP (XML Data Package) Formatted Document. The XDP is understood by Adobe Reader 7.x and above. The XDP has 3 parts: Header, Form Fields Data, and Footer which has a link to the empty LiveCycle PDF. So build the XDP String Variable by Concat , Concat, Concat ...etc... then concat until you are done. You must use a Response Object to set he content type as XDP and write the content of the XDP into the Response. If you XDP String Variable is formatted as per the rules, it will work. XML Does not like some characters, so you must encode them so that they are interpreted properly by IE on the Client.



The sample code I posted earlier has complete details.



If you still require help, please let me know.



Regard ....



Tarek.

Avatar

Former Community Member
Tarek:



Thank you sir. I'm i can gain to my situation with your knowledge, but let me clarify for you.



This is 100% server side operation, with the entire operation performed in the same directory. In my current testing case this would be the "planner" folder. Please reference my testing files to go along with my explanation



http://alexisgrand.com/planner/LoanAgreement.pdf



and



http://alexisgrand.com/planner/view.php?sort=LastName



Yes. I am using LiveCycle Designer (8.0)

=================================================

NOT a PDF form but rather an HTML form for submission of values to MYSQL DB. **Please note, in my situation this factor is not of importance, we just need a form to get the field values into a MYSQL DB table. But we do want our end result to be a populated PDF served to end-user (Me).



But I am currently using a short "dummy" form which happens to be a PDF form rather than an HTML form, but this is only because I just happened to have it around, and it is in fact "short" and good for the purpose of me testing, once I get the operation successfully working I will replace with a longer HTML form, and replace all of the parameters accordingly to fit my actual form (which has 68 input fields rather than 5 ;)

=================================================

The PDF form to be populated and served to end-user (Me) will be the "un-populated" PDF form that always resides on the server.

=================================================

now the client has submitted the form and all value have been inserted into the MYSQL DB table

=================================================

I have a repository for all of the form submissions.

here -- http://alexisgrand.com/planner/view.php?sort=LastName

each form submission has a corresponding "VIEW PDF" link, which looks something like this



http://alexisgrand.com/planner/viewpdf.php?id=25



25 being row id in the MYSQL DB table for this particular form submission, this row contains all of the field values of the submitted , that will be eventually insterted into the blank PDF Form in the directory.

==================================================

http://alexisgrand.com/planner/viewpdf.php?id=25



notice "viewpdf.php" when this page is activated (by clicking the VIEW PDF link) it requests all of the form values needed, and saves them as variables. after variables are saved viewpdf.php creates the FDF structure, which looks like the following:



require_once( 'forge_fdf.php' ); <--- remember this***



$fdf_data_strings= array('form1[0].#subform[0].#area[0].LastName[0]' => $pdf_LastName, 'form1[0].#subform[0].#area[0].FirstName[0]' => $pdf_FirstName, 'form1[0].#subform[0].#area[0].EMail[0]' => $pdf_EMail, 'form1[0].#subform[0].#area[0].IDNum[0]' => $pdf_IDNum, 'form1[0].#subform[0].#area[0].NetID[0]' => $pdf_NetID, 'form1[0].#subform[0].#area[0].DateSubmitted[0]' => $pdf_DateSubmitted);

$fdf_data_names= array();

==================================================

viewpdf.php then calls on forge_fdf.php which creates an actual "FDF.tmp" on the server (of course in the planner folder)



the FDF.tmp file if opened in a plain text editor would look like this:



%FDF-1.2

%âãÏÓ

1 0 obj

<<

/FDF << /Fields [ << /T (form1[0]) /Kids [ << /T (#subform[0]) /Kids [ << /T (#area[0]) /Kids [ << /T (LastName[0]) /V (Trip) /ClrF 2 /ClrFf 1 >>

<< /T (FirstName[0]) /V (Chris) /ClrF 2 /ClrFf 1 >>

<< /T (EMail[0]) /V (chris@chris.com) /ClrF 2 /ClrFf 1 >>

<< /T (IDNum[0]) /V (777777777) /ClrF 2 /ClrFf 1 >>

<< /T (NetID[0]) /V (555-55-5555) /ClrF 2 /ClrFf 1 >>

<< /T (DateSubmitted[0]) /V (2008-02-01) /ClrF 2 /ClrFf 1 >>

] >>

] >>

] >>

<< /T (id) /V (4) /ClrF 2 /ClrFf 1 >>

]

>>

>>

endobj

trailer

<<

/Root 1 0 R



>>

%%EOF

==================================================

pdftk.exe is now called upon to stuff the FDF into the blank PDF form, flatten it and serve it up to the end-user -- yes, that would be Me ;)



DONE!

==================================================

My problem is that this workd GREAT when tested locally http://localhost/planner/ on my Windows machine using WAMP Server



but remotely (where I need it) I use a shared hosting provider on a Linux server, and cannot use pdftk.exe being that is a Win32 based app. (Windows)



there are Linux builds of pdftk, but I am restricted from any installations or shell access.

===================================================



so I decided it was that important that i would purchase another hosting plan just to handle this operation, and it would need to be a Windows server to use the pdftk.exe, with the ability to use MYSQL and PHP scripting.



Ok so i have got that taken care of a hosting provider @ only $5 per month plenty of what with more than what i need.



BUT i am not able to control READ, WRITE, EXECUTE permisssions from the control panel, only READ & WRITE.



So after many emails and days, and repeating the sceanrio over and over to tech support, even thought everything is outlined in my Support tickets, and I even made a screen recording demo for tech support.



They have told me that the folder as full permisssions and pdftk.exe is permissioned to EXECUTE.



I get nothing! Just to test, i turned the option off, which deletes the FDF.tmp file immedietly (very quickly) after the merging. Now the FDF.tmp files remain on the planner folder.



They are named like so in this case fdf4AE.tmp, fdf4AF.tmp, fdf4B0.tmp, etc..



well when i activate the viewpdf.php page to do the merging and serve the file up to end-user , tmp files are ever created?? as I connect and reconnect to the directory via FTP to check, and also view from the File Manager in the hosting Control Panel. No tmp files.



so thinking they may be hidden, I move a view tmp file created locally onto the server, and they show up wihtout a problem.



this is were I am stuck at.

==============================================



NOW what i have done as a temporary remedy, and the next best thing, which definately is not what Im looking for, is following, i have done this one my orginal remote Linux server.



I have to ave me from typing, I ave created the same scenario as above, but eliminated forge_pdf.php and pdftk.exe from the equation, and intstead, an XML file is served up to end user rather than a finalized PDF. the XML file has to be imported into the unpopulated PDF form, via the Import function under manage forms in Acrobat Pro 8.



you may think this is not big deal, but this isn't close to what I am need of.



so I believe I covered everything. The funny thing is that I do not formally know PHP, I have just examined code and figured everything out thus far.



So does your answer vary in this situation? One thing i can say is that on the Windows server I am using I can use ASP.NET for scripting, so I thought you may be able to provide a solution?

Avatar

Level 8
Dear Chris,



I think I understand your problem bettwr now, ... I HOPE !



Using pdftk.EXE, it works locally, but when it is hosted live at the provider company, it does not work due to some limitations ...etc.



I tried the link you gave me to open the populated PDF, when I click it, I get a dialog box asking me to Open the PDF, then I get error of some kind.... it did not work on my side probably due to the reasons you mentioned.



Ok, do you want my advise ...??



- DROP pdftk.EXE.



- FDF Method is OBSOLETE ... DO NOT USE IT.



- My understanding is that FDF method should not work with LiveCycle PDF, they are 2 different formats and technologies.



- Use XDP method to merge Data Fields with LiveCycle Form and push back the result to the Client.



- CONSIDER using PDF on the Client Side and Submit the Result to Server using JavaScript (under Adobe). This method will save you the need to convert HTML to PDF and you can get the PDF as-is on the server, even with Digital Signatures protected, if used.



- When the client fills the PDF and Submit as XDP, on the Server, you can retrieve the ENTIRE PDF and Save it to Local Folder with the name you like. Later, you can just compose a link to this file, and no need to do any Data Merging what so ever, and this link can be used to render the same filled PDF with a click of a button. In addition to that, when the form has been submitted to the server, you can still retrieve the form field values and do what ever you want with them.



- Remeber the value of using PDF form in the beginning. Can you visualize the difference between HTML Form and PDF Form ? I am sure you know the difference, but one important difference you may have missed ! The PDF Form, once Digitally Singed by the Author, its Security Identity is PRESERVED and PROTECTED, and no one is "supposed" to be able to break it. And if you try to break it, the Identity will be erased. Also, if you try to make change AFTER it is Digitally Signed, the Attribute of the Digital Signature will be marked as "Changed After Signature". Also, with EACH Digital Siganture, you have a FULL Version of the PDF SAVED for ever inside the SAME PDF, and you always have the option to view the version of the PDF at the time of the Signature and remove all the changes that ocurred after a given signature. It is a TRUE Electronic Replacement of the Real World Forms.



I can spend more than 30 minutes wirting about the benefits of using PDF instead of HTML for Creating the Form at the Client Side.



I hope this helps.



Tarek.

Avatar

Former Community Member
Thank you, but it definately needs to be an HTML form, as this form is passed to folks all ovver the country to fill out and any one that doesnt have Reader or the correct version.. even though to you and I is just a matter of a couple minutes to resolve but I have seen clients that are not so saavy, just see this as frustrating and move on.



so the HTML form is the solution for the client, and right now everything to set, that onc e aPlanner is submitted, and email link would go out to myself, (producing a fully filled Planner, and seperate emails sent to different folks in the workflow, but with certain fields ommitted for each recipeitn depenfing on there department and if the criteria is relevant to them.



if i could just get thed data merged, everything else is in place.. and life would be even better :)

Avatar

Former Community Member
Hi Tarek



I just want to say thank you for the article it's been a great deal of help. I have only one question. Do you know of any way I can set the values of no fillible objects? For example. I want to fill in the submit URL of a button or change the text in a text object. Is this possible?