PDA

View Full Version : Problem using jPDFText.jar



bsnuggs76
03-15-2011, 10:42 AM
I'm trying to use jPDFText.jar from Qoppa (http://www.qoppa.com/pdftext/jptindex.html).

I've used java libraries before, but I'm having a problem with this one.

Relevant service program lines:

D PdfText S O CLASS(*JAVA
D :'com.qoppa.pdfText.PDFText')
D PdfPassword S O CLASS(*JAVA
D :'com.qoppa.pdf.PDFPassword')
...
D new_PdfText...
D PR like(PdfText)
D ExtProc(*JAVA
D :'com.qoppa.pdfText.PDFText'
D :*CONSTRUCTOR)
D inFileName like(jString)
D inPDFPassword like(PdfPassword)
D new_PdfPassword...
D PR like(PdfPassword)
D ExtProc(*JAVA
D :'com.qoppa.pdf.PDFPassword'
D :*CONSTRUCTOR)
D inString like(jString)

Program usage:

#lcstmf = tgdpath;
#lcstmfj = new_String(%trim(#lcstmf));
#lcpwdj = new_String(#lcblank);
#lcpdfpwd = new_PdfPassword(#lcpwdj);
#lcdocument = new_PdfText(#lcstmfj:#lcpdfpwd);


I get this error:

Message . . . . : Java exception received when calling Java method.
Cause . . . . . : RPG procedure SOR005 in program WORKLIBR/SOR005CL receiv
Java exception "java.lang.NoSuchMethodError: < init >" when calling method
"< init >" with signature "(Ljava.lang.String;Lcom.qoppa.pdf.PDFPassword;)V"
in class "com.qoppa.pdfText.PDFText".

...but when I run STRQSH CMD('javap -s com.qoppa.pdfText.PDFText'), I can see this signature (along with others):


public com.qoppa.pdfText.PDFText(java.lang.String, com.qoppa.pdf.IPassword)
throws com.qoppa.pdf.PDFException;
Signature: (Ljava/lang/String;Lcom/qoppa/pdf/IPassword;)V


To me, my signature matches the one seen in javap output. Why is the error being thrown?

T.Snyder
03-15-2011, 01:08 PM
I don't use jPDFText, but I believe this will fix your problem.



D PdfText S O CLASS(*JAVA
D :'com.qoppa.pdfText.PDFText')
D PdfPassword S O CLASS(*JAVA
D :'com.qoppa.pdf.PDFPassword')
<b>D IPassword S O CLASS(*JAVA
D :'com.qoppa.pdf.IPassword')</b>
...
D new_PdfText...
D PR like(PdfText)
D ExtProc(*JAVA
D :'com.qoppa.pdfText.PDFText'
D :*CONSTRUCTOR)
D inFileName like(jString)
D inPDFPassword <b>like(IPassword)</b>
D new_PdfPassword...
D PR like(PdfPassword)
D ExtProc(*JAVA
D :'com.qoppa.pdf.PDFPassword'
D :*CONSTRUCTOR)
D inString like(jString)


I believe you have my book Advanced Integrated RPG. You could find more information on this on pages 171 and 172 that discusses polymorphism and it's usage with prototypes.

In summary, PDFPassword implements the IPassword interface, but the signature is different for each object when trying to find the matching signature on the prototype.

As I said, I don't have this package installed, so there may be a typo because I typed it off the cuff. But, I think you get the idea.

Enjoy,
Tom

bsnuggs76
03-15-2011, 01:25 PM
Thanks Tom. That was the problem.

I'm forced to use this other library because of the problems I'm having with iText (http://www.mcpressonline.com/forum/showthread.php?18074-quot-Length-problem-quot-error-in).

bsnuggs76
03-15-2011, 01:50 PM
I would love to use iText instead (so I wouldn't have to force the usage of the 5.0 version of JVM...and PAY for the jar file). Any idea's on what would cause the problem I was originally having?
http://www.mcpressonline.com/forum/showthread.php?18074-quot-Length-problem-quot-error-in

Here is the PDF I was trying to read:
http://www.uspto.gov/web/trademarks/tmog/20110118_OG.pdf

T.Snyder
03-15-2011, 01:58 PM
Great! I'm glad that was the fix for you.

Sorry I don't have any more information on your original problem. I've played with the PDF text extractor in iText, but I never used the text extractor under full production load so I don't have any additional information on the limitations that you've run into.

I plan on updating to the latest version soon, and I'll see if I could run into your problem with a possible solution while I'm at it. But I'm sure you'll be happily using your jPDFText version by then :)

Glad I could help, Good luck with your jPDFText project!
Tom

T.Snyder
03-15-2011, 02:05 PM
Downloaded. I was going to ask you for a sample, but I wasn't sure if it was classified or not. This is an awesome example! Lots of pages and tons of text for validation. I don't know when I'll get the chance to try it out, but I'll let you know if I come up with anything.

I don't know if it makes a difference, but have you tried the latest version of iText when you were doing your development?

bsnuggs76
03-16-2011, 03:53 PM
No. The latest version requires Java 5.0 and I was having some problems with that JVM version on my AS400.

I hit another snag with jPDFText, though.

We ended up buying it and they use a setKey method to unlock production use of the library. I can't seem to get that method to work correctly. I'm sure it's something minor.

Here's the javadoc:
http://www.qoppa.com/pdftext/guide/javadoc/com/qoppa/pdfText/PDFText.html#setKey(java.lang.String)

Here's the signature from "javap -s com.qoppa.pdfText.PDFText":


public static boolean setKey(java.lang.String);
Signature: (Ljava/lang/String;)Z


Here's my prototype:


D PdfText_SetKey...
D PR n
D EXTPROC(*JAVA
D :'com.qoppa.pdfText.PDFText'
D :'setKey')
D static
D inString like(jString)


Here's my app code (the setkey only needs to occur once in the program):


if not #lcsetkey;
#lclickey = new_String(%trim(jpdflickey));
eval #lcbool = PdfText_SetKey(#lcdocument:#lclickey);
eval #lcsetkey = *on;
endif;


I get this error:


Message . . . . : Java exception received when calling Java method.
Cause . . . . . : RPG procedure SOR005 in program WORKLIBR/SOR005CL received
Java exception "java.lang.NoSuchMethodError: setKey" when calling method
"setKey" with signature "(Ljava.lang.String;)Z" in class
"com.qoppa.pdfText.PDFText".


I have a feeling the problem is in my prototype. If the return type is boolean in a java function, how would I note that in the prototype?

bsnuggs76
03-17-2011, 08:13 AM
I changed the prototype to this:


D PdfText_setKey...
D PR like(jboolean)
D EXTPROC(*JAVA
D :'com.qoppa.pdfText.PDFText'
D :'setKey')
D static
D inString like(jString)


...and changed the app code to this (since it was a static method it needed no object reference):


if not #lcsetkey;
#lclickey = new_String(%trim(jpdflickey));
eval #lcjbool = PdfText_SetKey(#lclickey);
eval #lcsetkey = *on;
endif;


Now I get a compile error:

*RNF3967 30 1 The datatype is not allowed for the return value of a method.

...even through the datatype is the is the correct one.

bsnuggs76
03-17-2011, 08:42 AM
Changed the prototype back to the original after finding this blurb on a google search:

The returned value is specified as N, which maps to the Java boolean data type

That...along with the change of not passing it the object reference got it to compile and run without a runtime error.

It still fails on any page > 10...which is a limitation of the trial version...which means the setkey didn't actually work.

I'll call Qoppa at this point.