B4J Question [SOLVED] Show a pdf file inside a B4j App

giovit

Member
Licensed User
Longtime User
Based on this post https://www.b4x.com/android/forum/threads/show-pdf-in-web-view.52814/#post-330898, I supposed it was posible to open a local PDF file in a Webview node, so I tried to open a pdf file with a Webview but until now it was impossible to me to find a way to do it. I creates a text file in the same directory and with the same name than the PDF file, and I can view it with Webview, so the path I'm using is correct.
So the question is, is there other altenative? or definitively is not possible to do it.
or perhaps a step I'm missing.
I also tried with jScriptEngine, but no luck until now.

Here is the code that work for showing a .txt file but if you change the file for a PDF nothing will be shown
B4X:
wvDocument.LoadUrl("file:///e:/" & "Invoice.txt")

Thanks in advance
 

Daestrum

Expert
Licensed User
Longtime User
You could use
B4X:
fx.ShowExternalDocument("path/to/your/pdf/file.pdf")
and allows the pdf viewer on the system to display the file.

or

Have a look at https://kbdeveloper.qoppa.com/?p=2812
This took maybe 15 lines of code (pure java) to enable viewing of a pdf file in a real window (not a webview) it also adds print and other functions.
The demo has a watermark, but seems to work fine. Didn't look at the cost of full version.
 
Last edited:
Upvote 0

giovit

Member
Licensed User
Longtime User
Thank you Dastrum, I want to implement an application to scan, name, rename, save and move pdf files because all my documents (invoices, legal documents, bank transactions, etc) are scanned and need to be saved to differents directory to keep its well organized an with a consisten file name, the file name depends of the relevants parametes of the documents.
So I whished just to show the pdf file, once it is scanned, inside the application to view and copy those relevant parameter, assign a category and an owner and send it to its corresponding directory.

If I use fx.ShowExternalDocument("path/to/your/pdf/file.pdf") it will open adobe or any other pdf reader in full screen and I have to swich back and forth, to copy those parameters.

I started to implement this app in excel, then I wished to try with B4J.

This took maybe 15 lines of code (pure java) to enable viewing of a pdf file in a real window (not a webview)

On the other side, I have never programmed in Java, and the question is: When you say enable viewing of a pdf file in a real window, it means not inside a B4J Layout?

Thank you again
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
When you say enable viewing of a pdf file in a real window, it means not inside a B4J Layout

Sorry I phrased it badly. The PDFViewerFX software returns a borderpane that can be added to the mainform's rootpane for example.
 
Upvote 0

giovit

Member
Licensed User
Longtime User
That is a good news!
Well, I will try to learn a bit of java and how to wrap the library and insert it to a pane

Thanks one more time
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
This was the entire code I used (needs javaobject library)
B4X:
#Region Project Attributes 
 #MainFormWidth: 600
 #MainFormHeight: 400 
 #AdditionalJar: c:/temp/jpdfviewerfx.jar   
#End Region
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Dim inline As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 inline = Me
 MainForm.Show
' c:/temp/pdftest.pdf in the following line is the name of the pdf file
 MainForm.RootPane.AddNode(inline.RunMethod("newViewer",Array("c:/temp/pdftest.pdf")),0,0,600,600)
End Sub
#if java
import com.qoppa.pdfViewerFX.PDFViewer;
import com.qoppa.pdf.PDFException;
 
import javafx.scene.layout.BorderPane;
static PDFViewer myViewer;
 
public static BorderPane newViewer(String pdf){
 myViewer = new PDFViewer();
 try{
    myViewer.loadPDF(pdf);
 }
 catch (PDFException pdferr){
    System.out.println(pdferr);
 }
 return new BorderPane(myViewer);
}
#end if
 
Upvote 0

giovit

Member
Licensed User
Longtime User
It work Excelent!
Thank you very much
I know this forum is for help to solve and not for give entire solved code, but some time we need a bit of some extra code to have an idea and continue investigating.
 
Upvote 0
Top