ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

iText 5.1.1

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • iText 5.1.1

    Is anyone running any apps using java calls to iText with the 5.1.1 version?? I'm trying to write just a quick one line output PDF document using the iText example as a guide, and converting it to RPG / Java calls.

    Here is their example code:

    Code:
        public void createPdf(String filename)
     throws DocumentException, IOException {
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter.getInstance(document, new FileOutputStream(filename));
            // step 3
            document.open();
    [COLOR=#ff0000]       // step 4
            document.add(new Paragraph("Hello World!"));
    [/COLOR]       // step 5
            document.close();
        }
    }
    My step 1, 2, 3, & 5 work in my RPG app. If I omit step 4, then the program runs, but fails on the close because there are no pages in the document. Since I didnt output any, this is expected.

    The problem is with step 4. When I call the document.add method and pass it a "PARAGRAPH", the method fails because it doesnt find a method. Sure enough, when I look at the document class in the itextpdf-5.1.1.jar file, I dont see an add method with a paragraph being passed.

    Yet, they have one in their example.

    So I'm just checking to see if anyone has any code with this current release going. Cause I'm going blind trying to figure out how they are able to call a method in a class that I dont see listed.
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

  • #2
    Re: iText 5.1.1

    you'll have to instantiate the paragraph object. my prototype looks like this:
    Code:
                                                                        
    dnew_Paragraph    pr                  ExtProc(*JAVA                 
    d                                     :'com.lowagie.text.Paragraph' 
    d                                     :*CONSTRUCTOR)                
    d                                     like(iTextParagraph)          
    d prString                            like(jString)
    to call i built a procedure like this:
    Code:
    piText_Add_Text_To_Doc...                                      
    p                 b                   Export                   
    diText_Add_Text_To_Doc...                                      
    d                 pi                                           
    d TextData                   65535a   Options(*Varsize) Const  
    d DataLength                    10i 0 Const                    
    doutElement       s                   like(jString)            
    doutParagraph     s                   like(iTextParagraph)     
     /free                                                         
        outElement = new_String( %Subst(TextData:1:DataLength) );  
        outParagraph = new_Paragraph( outElement );                
        Success = Add_To_Doc( Doc : outParagraph );                
     /end-free                                                     
    piText_Add_Text_To_Doc...                                      
    p                 e
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: iText 5.1.1

      Regarding the documentation it defines an add method for adding an Element object.


      You can click on the Element link and see that this is an interface. An interface is like a contract, any classes that implement the Element interface must implement the methods from the Element interface. It also means that you cannot create an Element object, only objects of classes that implement an Element.


      The Paragraph object implements the Element interface. This means that it must be possible to call all of the methods of an Element on a Paragraph. It also means that anywhere you have a method parameter that takes an Element, you can pass in a Paragraph. This is true of any object that implements Element. E.G. Chunk or PdfPTable.
      Ben

      Comment


      • #4
        Re: iText 5.1.1

        Hey Tom & Ben,

        First thanks.

        @Ben - yea, and it appears that its implemented the same way from back in 2.1.2 The method error I was getting was throwing me for a loop, because it acted like it didnt like a paragraph being passed to to the Document.add. That shouldnt be the problem, so my prototype must be screwed. (Thats what I get for trying to quickly free-hand the program.)

        @Tom - That's pretty much what I had in a few programs I wrote for the 2.1.2 version of iText. Those programs were on another machine I had on lease, and I backed them up to tape before sending the machine back to IBM. I noticed that the signatures in the classes have changed for 5.1.1 (ie: 'com.lowagie.text.Paragraph' is now 'com.itextpdf.text.Paragraph' , etc) so instead of going thru the tapes and restoring and modifying the old programs, I just decided to write a quick one to try the new api version out. The quick little program then took up a chunk of my weekend.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment


        • #5
          Re: iText 5.1.1

          Originally posted by MichaelCatalani View Post
          Hey Tom & Ben,

          First thanks.

          @Ben - yea, and it appears that its implemented the same way from back in 2.1.2 The method error I was getting was throwing me for a loop, because it acted like it didnt like a paragraph being passed to to the Document.add. That shouldnt be the problem, so my prototype must be screwed. (Thats what I get for trying to quickly free-hand the program.)

          @Tom - That's pretty much what I had in a few programs I wrote for the 2.1.2 version of iText. Those programs were on another machine I had on lease, and I backed them up to tape before sending the machine back to IBM. I noticed that the signatures in the classes have changed for 5.1.1 (ie: 'com.lowagie.text.Paragraph' is now 'com.itextpdf.text.Paragraph' , etc) so instead of going thru the tapes and restoring and modifying the old programs, I just decided to write a quick one to try the new api version out. The quick little program then took up a chunk of my weekend.
          may I won't have to upgrade to 5.1.1 then lol
          I'm not anti-social, I just don't like people -Tommy Holden

          Comment


          • #6
            Re: iText 5.1.1

            Originally posted by tomholden View Post
            may I won't have to upgrade to 5.1.1 then lol
            haha, my first post was simply going to be "has anyone created a service program with java calls for iText 5.1.1 that I can steal / borrow??
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: iText 5.1.1

              Originally posted by MichaelCatalani View Post
              haha, my first post was simply going to be "has anyone created a service program with java calls for iText 5.1.1 that I can steal / borrow??
              well i could do one but it definitely wouldn't be quick...
              I'm not anti-social, I just don't like people -Tommy Holden

              Comment


              • #8
                Re: iText 5.1.1

                Originally posted by BenThurley View Post
                Regarding the documentation it defines an add method for adding an Element object.


                You can click on the Element link and see that this is an interface. An interface is like a contract, any classes that implement the Element interface must implement the methods from the Element interface. It also means that you cannot create an Element object, only objects of classes that implement an Element.


                The Paragraph object implements the Element interface. This means that it must be possible to call all of the methods of an Element on a Paragraph. It also means that anywhere you have a method parameter that takes an Element, you can pass in a Paragraph. This is true of any object that implements Element. E.G. Chunk or PdfPTable.
                http://api.itextpdf.com/itext/com/it...Paragraph.html
                Thanks Ben, this ended up being the issue. The prototype for the Document.add has to be defined with an ELEMENT parameter. I can pass it a paragraph parameter, but it has to be defined with an element parameter in the prototype so that the method can be found. It's easy to miss when one is working of of a java example that is passing a paragraph, with no mention of an element.
                Michael Catalani
                IS Director, eCommerce & Web Development
                Acceptance Insurance Corporation
                www.AcceptanceInsurance.com
                www.ProvatoSys.com

                Comment

                Working...
                X