15 Replies Latest reply on Apr 21, 2010 11:04 AM by AKloft

    Get a document's content

    AKloft Level 2

      Hi everyone,

       

      I'm currently using LiveCycle ES 8.0 and am receiving a TIFF image as an input document (Document variable).  I need to take this document, get it's content (the image itself), and convert it to a String variable that I can store into a database.  Once it is in the database, a webservice call will get that image byte code and put it into a form's image field.

       

      Does anyone know of a way to accomplish this in ES 8.0?  Thanks in advance, and if I need to be more specific, please let me know.

      Alex

        • 1. Re: Get a document's content
          Jasmin Charbonneau Level 4

          You could use the xPath function getDocContentBase64 to convert your document into a base 64 encoded string.

           

          The insert it into the database using the JDBC service.

           

          Your xpath would look something like /process_data/@myString = getDocContentBase64(/process_data/@myDoc)

           

          Jasmin

          • 2. Re: Get a document's content
            AKloft Level 2

            Hi Jasmin,

             

            Thanks for your response.  I actually couldn't find that function in 8.0.  I know it is present in 8.2 and I was using it, but had to import my process to an 8.0 environment and this functionality seemed to stop working.  I searched every function for each data type but couldn't find it.

             

            Thanks,

            Alex

            • 3. Re: Get a document's content
              Jasmin Charbonneau Level 4

              Sorry...That works only in 8.2!

               

              Do you have to convert it to a string before storing in the database.

               

              You could use the Execute SQL Statement and use the parameterized query option to store the document variable into a BLOB in the database.

               

              Jasmin

              • 4. Re: Get a document's content
                Jasmin Charbonneau Level 4

                ...or you could write a custom component to do it in 8.0.

                 

                Jasmin

                • 5. Re: Get a document's content
                  AKloft Level 2

                  The way the stored procedure is set up, yes I do have to have it converted to a string.  if I just pass in the document variable itself, it doesn't put the byte code in.  I was thinking of just doing a custom script, but wasn't sure because after looking at the API for com.adobe.idp.Document, I tried reading everything in, but it only showed 3 characters in the output (II*) but it said the byte[] i was using had a size of 45015, which is correct, but the data didn't reflect this.

                  • 6. Re: Get a document's content
                    Jasmin Charbonneau Level 4

                    You need to get the input stream from the document variable (InputStream inputStream = DocVar.getInputStream())

                     

                    and then do a search on the web to convert InputStream to String and that should do it.

                     

                    Jasmin

                    • 7. Re: Get a document's content
                      AKloft Level 2

                      Hi Jasmin,

                       

                      Thanks for your response.  Here is the code I am attempting:

                       

                      com.adobe.idp.Document imageClob = patExecContext.getProcessDataValue("/process_data/@imgToConvert");

                      InputStream is = imageClob.getInputStream();

                      String imgBytes = "";
                      String line = "";

                      try{
                          BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                          while((line = reader.readLine()) != null) {
                              imgBytes += line;
                          }
                      }
                      catch(IOException ioe){
                          System.out.println("Error getting document bytes in Convert TIFF to Clob");
                      }
                      finally{
                          is.close();
                      }

                      patExecContext.setProcessDataValue("/process_data/@sClobOutput", imgBytes);

                       

                      Unfortunately, it is still putting out just II* as the image byte code.  I'm wondering if my ISR's character set could be not getting one of the characters?  Any further advice you have would be greatly appreciated.

                       

                      edit: Here is a screenshot of the image in a text editor:

                      image bytes.JPG

                       

                      The black boxed codes are the problem-causing elements I think.

                       


                      Thanks,

                      Alex

                      • 8. Re: Get a document's content
                        AKloft Level 2

                        Jasmin,

                         

                        My requirements have changed a bit.  I now have a BLOB field that I need to put the byte[] data in.

                         

                        I believe I am successfully retreiving the byte[] data from the document now, but I just have a quick question of:  Does LiveCycle ES come with the oracle.sql packages?

                         

                        Thanks,

                        Alex

                        • 9. Re: Get a document's content
                          Jasmin Charbonneau Level 4

                          When you install, you need to have the proper database driver so we can create our data source. I believe for Oracle the driver is ojdbc6.jar.

                           

                          That file does contain an oracle.sql package.

                           

                          As per the installation instruction it should be copied to the following folder:

                           

                          Copy the ojdbc6.jar file from the [LiveCycleES2 root]/lib/db/oracle directory to the
                          [jboss bam root]/server/all/lib directory.

                           

                          Jasmin

                          1 person found this helpful
                          • 10. Re: Get a document's content
                            AKloft Level 2

                            Hi Jasmin,

                             

                            I cannot begin to express my gratitude to you for being so patient with me

                             

                            I'm wondering if I can write the following in an Execute Script, or if I will need a Custom Component:

                             

                            1. Call a stored procedure passing in an Empty_Blob with other parameters (setting the BLOB field to null)

                            2. Do a select statement on the row created by the stored procedure (SELECT BLOB_FIELD FROM TABLE WHERE ID = XXXX FOR UPDATE)

                            3. Get the BLOB from the ResultSet (rs.getBlob(1))

                            4. stored the byte[] from the Document object to the BLOB and then call a connection.commit()

                             

                            Is this possible/allowed in an ExecuteScript?

                             

                            Thanks again,

                            Alex

                            • 11. Re: Get a document's content
                              Jasmin Charbonneau Level 4

                              Yes. You can do it in an Execute Script.

                               

                              In fact I've posted the code to do something similar a while ago.

                               

                              Check the following post: http://forums.adobe.com/message/1366379#1366379

                               

                              In there is say that it's not possible to pass a document object to the jdbc service, but that's not true. You can do it if you use the parametrized query option.

                               

                              The code you see there was run within the Execute Script.

                               

                              However I still think you should be able to do all that using the out of the box operation within the JDBC service. But both ways should work.

                               

                              Jasmin

                              • 12. Re: Get a document's content
                                AKloft Level 2

                                You mean I should be able to just use the Execute Query from JDBC to do something like:

                                        {call sp(?,?,?,?,?)}

                                set up the parameters for something like: int, int, int, int, clob  and then get an output string from the Execute Query?

                                 

                                I couldn't get it to work like that when I tried it a while back.

                                 

                                I'll give the execute script a try and see what I can make of it.

                                 

                                Thanks,

                                Alex

                                • 13. Re: Get a document's content
                                  AKloft Level 2

                                  Thank You! It worked like a charm!

                                  • 14. Re: Get a document's content
                                    Jasmin Charbonneau Level 4

                                    Well, if it's a stored procedure, you should use the Call Stored Procedure from the JDBC service.

                                     

                                    But yes, you should be able to use the call sp(?,?,?) notation.

                                     

                                    I'm glad you got it to work.

                                     

                                    Jasmin

                                    • 15. Re: Get a document's content
                                      AKloft Level 2

                                      Couldn't have gotten it working and look so clean if it weren't for you, so YOU got it working