B4J Question PDFBox to load from URL

Markos

Active Member
Licensed User
Longtime User
Dear All,

I would like to load a pdf file from a URL using either the rewrap of pdfbox or other class or object. Any suggestions most welcomed.

Thanks
 

stevel05

Expert
Licensed User
Longtime User
This appears to work:

B4X:
    Dim Job As HttpJob
    Job.Initialize("Job1",Me)
    Job.Download("https://www.b4x.com/android/forum/attachments/sample-pdf.85740/")
    
    Wait For (Job) JobDone(j As HttpJob)
    
    If j.Success = False Then Return
    
    Dim Doc As PDDocument
    Doc.Initialize("Doc")
    Dim Jo As JavaObject = Doc
    Doc = Jo.RunMethod("load",Array(j.GetInputStream))
    
    Log(Doc)
    Dim p1 As PDPage = Doc.GetPage(0)
    Log(p1)

But I don't know how it will integrate with DonManfreds Implementation of the library. Perhaps if you ask him, he will take a look at implementing load from input stream and also with password..
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
But I don't know how it will integrate with DonManfreds Implementation of the library. Perhaps if you ask him, he will take a look at implementing load from input stream and also with password..
Added Initialize3(eventprefix, inputstream) and Initialize4(eventprefix, inputstream, password)
 

Attachments

  • PDFBoxV0.29.zip
    150.7 KB · Views: 220
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Added Initialize3(eventprefix, inputstream) and Initialize4(eventprefix, inputstream, password)
This nicely streamlines your recent enhancements for future users but I was fine with the inclusions in the class as that was quite educational for me. So this new wrapper is to included using the additionaljar in conjunction with the PDFBox original jar yes? that is:

B4X:
    #AdditionalJar: pdfbox-app-2.0.19.jar
    #AdditionalJar: PDFBox.jar

No sorry this is to be added as a library via the tab and it is far more extensive than the wrapper I see you included many classes from the PDFBox now including Action and ActionURL etc
 
Last edited:
Upvote 0

Markos

Active Member
Licensed User
Longtime User
This nicely streamlines your recent enhancements for future users but I was fine with the inclusions in the class as that was quite educational for me. So this new wrapper is to included using the additionaljar in conjunction with the PDFBox original jar yes? that is:

B4X:
    #AdditionalJar: pdfbox-app-2.0.19.jar
    #AdditionalJar: PDFBox.jar

No sorry this is to be added as a library via the tab and it is far more extensive than the wrapper I see you included many classes from the PDFBox now including Action and ActionURL etc
There are quite a few more jar's to include using this PDFBox.jar, can you share what other jar's you require us to have on our b4j libraries folder?
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
There are quite a few more jar's to include using this PDFBox.jar, can you share what other jar's you require us to have on our b4j libraries folder?
As I added the PDFBox library and declared pdf2 as PDFBox and the compiler gave error dependencies as shown below:
B4X:
    #AdditionalJar: pdfbox-app-2.0.19.jar
    #AdditionalJar: fontbox-2.0.17.jar
    #AdditionalJar: commons-logging-1.2.jar
That being satisfied the compiler then reached a new stage but presented this compiler dependency missing:
B4X:
main._process_globals (java line: 492)
java.lang.NoClassDefFoundError: org/krysalis/barcode4j/output/CanvasProvider
    at b4j.example.main._process_globals(main.java:492)
    at b4j.example.main.initializeProcessGlobals(main.java:476)
    at b4j.example.main.start(main.java:34)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: org.krysalis.barcode4j.output.CanvasProvider
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 12 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Ok but the pdfbox wrapper sample app had..

B4X:
#AdditionalJar: pdfbox-app-2.0.14.jar

was it left there in error?

I just commented that lib out and it gave a file access error trying to open the pdf
 
Upvote 0

Markos

Active Member
Licensed User
Longtime User
Thanks.

No new problem just responding to your suggestion.

It works great as is. But if for correctness sake it needs to be a different lib included I'm happy to be your beta tester.

BTW I do like the wrapper in Class form as it offers me some flexibility to tweak but if you share both class and customised jar lib I will again be pleased to try both.. with guidance of course :)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Here are an example. Without the jar you used.

BTW I do like the wrapper in Class form
Write one.

Do not expect me to rewite a MEGA COMPLEX java library into a b4a class using javaobject.
 

Attachments

  • PDFBoxEx1.zip
    403.5 KB · Views: 220
Upvote 0
Top