• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[ANSWERED]VVPDF Merge Pdfs into one

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

  • [ANSWERED]VVPDF Merge Pdfs into one

    I am currently using iText in some other projects i wrote that allows me to merge PDFs into one.

    I am needing to do this in Valence using the vvPDF procedures...but didn't see any documentation on this being setup. The vvPDF Doc's say we can use any routine that iText uses we just have to write it ourselves.....so i thought i would ask before i write the custom code......... is there is any tips or help you could provide to make this easier. or maybe something is already in place and I am not seeing it. Wanted to ask before i took on the task!
    Thank you!

    Ryan

  • #2
    Hi Ryan,

    If you're using iText in other programs then you should already have a pretty good idea on what you need to do. As you've noticed, the vvPDF procedures include just the basics from iText to create a simple PDF file. To use more advanced iText functionality you'll need to call the specific iText Java methods directy. The VVITEXTD copysource in QCPYLESRC has most of the iText classes already defined, you just need to invoke them as appropriate from within your custom RPG program.

    For your reference, here's an example of a custom procedure we recently wrote in RPG for a client project in Ohio. This particular procedure adds a Phrase to a PDF document:

    Code:
         **--------------------------------------------             
         p addPhrase       b                                        
         d                 pi                                       
         d  pdfDoc                             const like(document) 
         d  inText                     1024a   const varying        
         d  inFont                             value likeDS($font)  
                                                                    
         d jText           s                   like(jstring)        
         d jFont           s                   like(Font)           
         d jPhrase         s                   like(iTextPhrase)    
         d jColor          s                   like(color)          
         d fontNameInt     s             10i 0                      
         d fontStyleInt    s             10i 0                      
                                                                    
         d cFontName       c                   const('FONT')        
         d cFontStyle      c                   const('FONTSTYLE')   
          /free                                                     
                                                                    
           // set string...                                         
           jText = iNew_String(inText);                             
                                                                    
           // prepare font name...                                  
           if inFont.name=*blanks;                                  
             inFont.name = 'TIMES_ROMAN';                           
           endif;                                                                 
           fontNameInt=getPDFconst(cFontName:inFont.name);                        
                                                                                  
           // prepare font style...                                               
           if inFont.bold;                                                        
             fontStyleInt+=getPDFconst(cFontStyle:'BOLD');                        
           endif;                                                                 
           if inFont.italic;                                                      
             fontStyleInt+=getPDFconst(cFontStyle:'ITALIC');                      
           endif;                                                                 
           if inFont.underline;                                                   
             fontStyleInt+=getPDFconst(cFontStyle:'UNDERLINE');                   
           endif;                                                                 
                                                                                  
           // set font                                                            
           jColor = iNew_Color_int(0:0:0);                                        
           jFont = iNew_Font_fssc(fontNameInt: inFont.Size: fontStyleInt: jcolor);
                                                                                  
           // inject it!                                                          
           jPhrase = iNew_Phrase_s_f(jtext : jfont);                              
           iDocument_add(pdfDoc : jPhrase);                                       
                                                                                  
           vvJava_freeLocalRef(jText);                                            
           vvJava_freeLocalRef(jColor);                                           
           vvJava_freeLocalRef(jFont);    
           vvJava_freeLocalRef(jPhrase);  
                                         
          /end-free                       
         p                 e
    On the input parms, "$font" is a global data structure defined as follows:
    Code:
         d $font           ds                   qualified       
         d   size                         2s 0  inz             
         d   bold                          n                    
         d   italic                        n                    
         d   underline                     n                    
         d   name                        20a
    Every other "like" referenced field is defined in the VVITEXTD copy source.

    -Rob

    Comment


    • #3
      got a good start on my code and was doing some initial testing...it kept saying that it could not find the constructor for PdfCopy...got to looking and it seems valence is using itext 2.1.5...and pdfcopy is not included in this release.... is it possible to run two different versions of itext and everything still work together...how might you handle this?

      Comment


      • #4
        This would be venturing a bit into uncharted waters, but I would suggest if you have access to a more recent version of iText that you just try replacing the 2.1.5 jar in Valence altogether. I'm assuming (but don't know for sure) that most if not all of the procedures in VVITEXTD would still work as currently defined. I'd be interested to hear how that works out for you as we start plotting plans for Valence 4.1.

        Note that if you change the iText jar name then you'll need to update the java class path to match. In Valence 3.2 this path is hard-coded in VVCALL, VVMAIL and VVPDF. In 4.0 the java classpath is a system setting, a bit more elegant.

        Comment


        • #5
          when i make a change to say vvpdf how am i suppose to compile? I am able to compile the module but not sure how to compile with the program option...also a lot of the newer versions of iText have changed their namespace......whereas it was com.lowagie.??? has been updated to com.itextpdf.??? so it seems all those references in the vvitextd will need to be corrected...
          thanks

          Comment


          • #6
            Once you've compiled the VVPDF module you need to update the service program.

            UPDSRVPGM (VALENCE32/VVSRVPGM) MODULE(VALENCE32/VVPDF)

            Depending on your OS, you may get an error on the update due to conflicting storage models within the service program. If that happens to you, try recompiling the module with COMPILEOPT('STGMDL(*SNGLVL)').

            Regarding changes to iText, we haven't really looked at anything beyond 2.1.7 ourselves, so good to know the namespace has changed. As I mentioned, uncharted waters! Unforutnately we're knee-deep in Valence 4.0 development and testing at the moment so we don't really have the resources to assist with iText upgrades right now. We'll definitely be interested in what you discover for future Valence releases though, so thanks for the info.

            -Rob

            Comment


            • #7
              No problem Rob...I understand. I wouldn't want to hold up release 4.0! (can't wait!) I appreciate the time you have given me already. I am having fun trying to figure this out on my own!

              Comment


              • #8
                I got this working! itext 2.1.5 does includes the PdfCopy classes I was just looking at incomplete documentation i found on a website. I unzipped the jar file from the vvdev32 and found the class to be there. Then it was as easy as prototyping the java classes i needed to use to merge my pdfs....thanks for the help. I didn't change any of the valence source...i did all the new stuff in my modules so I wouldn't lose the ability when we up

                Comment

                Working...
                X