1 Reply Latest reply on Apr 10, 2007 7:44 PM by mattschmatt

    Adobe XML/PDF API issue - cannot populate PDF within CF

      Hello. I download and installed the XPAAJ.jar file used for working with PDF files through Java. Ben Forta wrote an article about this and provided some examples. Anyway, I have the following code that works great until I call the InputFormData() method. When I remove the method, it works fine but gives the following error when I insert it. The method is the very last line in the code below.

      "The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values."
      ------------------------------------------------------------------------------------------ -------------------
      <!---open original PDF--->
      <cfset doc = "">
      <cfset docPath=GetDirectoryFromPath(GetBaseTemplatePath()) />
      <cfset PDFfile= docPath & "test.pdf" />
      <!---Create an empty input stream object in Java, then init it with the target PDF file--->
      <cfset inPdfFile = CreateObject("java", "java.io.FileInputStream")>
      <cfset inPdfFile.init(#PDFfile#)>
      <cfset PDFfactory=CreateObject("java", "com.adobe.pdf.PDFFactory")>
      <cfset doc = PDFFactory.openDocument(#inPdfFile#)>

      <!-- POPULATE THE FORM -->
      <cfset xmlString = "<root><patient_name>Eric Cartman</patient_name></root>">
      <cfset XMLBytes= xmlString.getBytes()>
      <cfset XMLStream = CreateObject("java", "java.io.ByteArrayInputStream")>
      <cfset XMLStream.init(XMLBytes)>
      <cfset byteCount = XMLStream.available()>
      <cfset doc.importFormData(XMLStream)>

      Any ideas? I can open the PDF and save it just fine. Also, the InputStream is not empty or null. The available() method shows that it contains 54 bytes. Yet I get the "null" error above.

      Thanks for any help.

      Sorry I almost forgot to add the sample code from the documentation Forta provided. I'm not sure if I was able to mimic the same code they provided in Java to CF.

      Example 3.1 Prepopulating a form by converting a string variable to a byte stream

      //Assign an XML schema to a string variable
      String formData ="<root><Amount>2500</Amount><FirstName>Jerry</FirstName>
      //Convert the string variable into a byte array
      byte[] inputData = formData.getBytes("UTF8");
      //Create an InputStream by calling the ByteArrayInputStream constructor
      InputStream formInputStream = new ByteArrayInputStream(inputData);
      //Call the PDFDocument object’s importFormData method