• unable to read pdf file attributes

    By Abhay Pandey 1 decade ago

    Hi Everyone,

    How to read attributes (Like pdf file version, creation date, author name etc) of a pdf file in lotus notes program using lotus script (Agent) or java script?

    This is required to validate pdf file, can anyone help on this?

     

    Thanks & Regards,

    Abhay

    • Some thoughts

      By Olli Kämäräinen 1 decade ago

      If you look at "SimplePdf ->pdftemplate-form –> "Click to add Pdf-form"-link –> code, there is example how to read pdf field

      names through LS2J. I've created simple java-function in iTextWrapper-library that reads pdf and returns list of field names

      back to Lotusscript. You might be able to get all the information you need, if you add some more functions to iTextWrapper..

      For example function for getting pdf-version could be:

      public String getPdfV(String tpath) {

          try {<br/>
              is = new FileInputStream(tpath);<br/>
              bos = new ByteArrayOutputStream();<br/>
              buf = new byte[1024];<br/>
              int len;<br/>
              while ((len = is.read(buf)) &gt; 0) <br/>
                  {<br/>
                      bos.write(buf, 0, len);<br/>
                  }<br/>
              data = bos.toByteArray();<br/>
              is.close();<br/>
              bos.close();<br/>
              <br/>
              reader = new PdfReader(data);<br/>
              String vers = Character.toString(reader.getPdfVersion());<br/>
                      <br/>
                  reader.close();<br/>
                  return vers;<br/>
          <br/>
                      <br/>
              }<br/>
                  catch(Exception e) {  <br/>
              e.printStackTrace();  <br/>
              return &quot;&quot;;<br/>
          } <br/>
          } <br/>
      



      And here is the Ls-code that could use it:

      Option Declare

      Uselsx "*javacon"

      Use "iTextWrapper"

      Sub Click(Source As Button)

          <br/>
      'HERE IS CODE TO GET PDF VERSION<br/>
      'PDF HANDLING IS DONE IN JAVA LIBRARY SO WE NEED TO PASS ONLY FILENAME<br/>
      Dim jSession As New JavaSession<br/>
      Dim pdfClass As JavaClass<br/>
      Dim pdfClient As JavaObject<br/>
      Dim jError As JavaError<br/>
      <br/>
      Set pdfClass = jSession.GetClass(&quot;iTextWrapper&quot;)<br/>
      Set pdfClient = pdfClass.CreateObject<br/>
      <br/>
      Msgbox(&quot;Pdf version is &quot; &amp; pdfClient.getPdfV(&quot;C:\mytest.pdf&quot;))<br/>
      <br/>
      Delete pdfClient<br/>
      



      End Sub