All,
Requirement:
We need to be able to populate retrieved database data into GSA’s SF1034 form (Here is an example of fillable PDF form found on GSA web site: http://www.gsa.gov/portal/forms/download/115462).
Current Approach:
- Converted the PDF into XDP file using Adobe LiveCycle.
- Read the XDP file and replace the <chunk /> and <xfa:data /> sections.
- Generate PDF using convertXDPtoPDF.
Question:
I have successfully read the XDP and original PDF in my C# code, but my replacement of data is not successful. I assume that I have replaced <xfa:data> incorrectly. How should it be done properly?
Maybe I have the wrong approach to tackle this problem, if that’s the case please let me know as well.
Code:
I am trying to use the following C# code to insert data into XDP string and generate it as a PDF.
try
{
using (StreamReader sr = newStreamReader(@"c:\Temp\PDF\SF1034-87.xdp"))
{
String line = sr.ReadToEnd();
string pdfTemplate1 = @"c:\Temp\PDF\SF1034-87.pdf";
FileStream stream1 = File.OpenRead(pdfTemplate1);
byte[] pdf1 = newbyte[stream1.Length];
stream1.Read(pdf1, 0, pdf1.Length);
stream1.Close();
// replace <chunk />
line = line.Replace("<chunk />", "<chunk>" + Convert.ToBase64String(pdf1) + "</chunk>");
// replace <xfa:data />
line = line.Replace("<xfa:data />", "<xfa:data><topmostSubform><Page1><VoucherNumber>ABC123</VoucherNumber ></Page1></topmostSubform></xfa:data>");
PDFUtilityServiceHelper _PDFUtilHelper1 = newPDFUtilityServiceHelper();
// Convert the XDP file to a PDF document
BLOB PDFin1 = newBLOB() { binaryData = System.Text.Encoding.UTF8.GetBytes(line) };
BLOB result1 = _PDFUtilHelper1.convertXDPtoPDF(PDFin1);
return result1.binaryData;
}
}
catch (Exception e)
{
}
and the mentioned PDFUtilityServiceHelper is constructed as following:
privatePDFUtilityServiceSoapBinding _PDFUtil = newPDFUtilityServiceSoapBinding();
public PDFUtilityServiceHelper()
{
_PDFUtil.Credentials = LiveCycleCredentials();
}
publicBLOB convertXDPtoPDF(BLOB inDoc)
{
return _PDFUtil.convertXDPtoPDF(inDoc);
}