Best way to display pdf file

gkumar

Active Member
Licensed User
Longtime User
Hi,

I am trying to display the .pdf file in my application, In other threads I read thru webview we can do it, so I tried like..

B4X:
WebViewDisplay.LoadHtml("<html><body><img src='file:///android_asset/filename.pdf'/></body></html>")

but it is showing a small icon with "?" .. could not able to find what is wrong here ?! inside html tag I tried "file" instead of "img", still not worked.

help me to find what is missing here .. or suggest me the best way to display the pdf file.

Thanks,:sign0085:
 

gkumar

Active Member
Licensed User
Longtime User
Thanks, any suggestions on external apps to display pdf's ? I was searching in web, but not sure which one will be supported in B4app. please let me know if you have any examples for this.
 
Upvote 0

gkumar

Active Member
Licensed User
Longtime User
Thanks kanaida,

I included the OpenPdf function and phone library in my code, and copied the file in application .apk path, and as well as in files tab thru "add files".

when I open the application is asks "Choose PDF Viewer" .. after choosing pdf viewer its shows "The document could not be opened" , could someone tell me what is the problem here ?

PS:- tested in emulator and device after installing adobe reader app.
 
Upvote 0

gkumar

Active Member
Licensed User
Longtime User
Thanks Erel, could you tell me what is the value for folder ?

I copied pdf file in "D:\projects\myapplicationfoldername\files\filename.pdf", I tried different combinations for folder input, but nothing works.

I am getting "The document path is not valid." Error.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Do not use Windows file and folder naming convention. Here is an example of a pdf file located on the root of the SD card.
B4X:
Dim folder   As String         :folder=File.DirRootExternal    'root of SD card on device
Dim filename As String         :filename="Kumar.pdf"   'this is the file name
OpenPDF("file://" & File.Combine(folder, filename))
 
Upvote 0

gkumar

Active Member
Licensed User
Longtime User
I tried this, and earlier tried like..
B4X:
OpenPDF("file://" & File.Combine(file.DirRootExternal, "filename.pdf"))

still getting the same error.

where should I copy the file ? or just adding the file into the files directory is enough ?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Do not put the file in a folder called:files. Simply copy the file from your PC if it is called: filename.pdf to the main folder of the SD memory card.
 
Upvote 0

gkumar

Active Member
Licensed User
Longtime User
You mean to copy the pdf file to the device ?
I am not using any devices, I am using emulator (AVD2.2), to test my application. cant we embed the pdf file in .apk ?
 
Upvote 0

gkumar

Active Member
Licensed User
Longtime User
Hi Erel,

As you suggested, Copied the file from dirassets to sd card folder, like..

B4X:
File.Copy(File.DirAssets, "Manual.pdf", File.DirDefaultExternal, "Manual.pdf")
OpenPDF("file://" & File.Combine(File.DirDefaultExternal, "Manual.pdf"))

now its working fine. Thanks.
 
Upvote 0

borland

Member
Licensed User
Longtime User
Hi Erel,

As you suggested, Copied the file from dirassets to sd card folder, like..

B4X:
File.Copy(File.DirAssets, "Manual.pdf", File.DirDefaultExternal, "Manual.pdf")
OpenPDF("file://" & File.Combine(File.DirDefaultExternal, "Manual.pdf"))

now its working fine. Thanks.
Your way I was successful, Thanks
 
Upvote 0

gwapong

Member
Licensed User
Longtime User
having a problem..please help
this is the error when i try to run it...

Parsing code. 0.01
Compiling code. 0.07
Compiling layouts code. 0.09
Generating R file. 0.19
Compiling generated Java code. Error
B4A line: 34
Activity.AddView(pdfv,0,0,-1,-1)
javac 1.6.0_20
src\b4a\example\main.java:250: cannot access cx.hell.android.lib.pagesview.PagesView
class file for cx.hell.android.lib.pagesview.PagesView not found
mostCurrent._activity.AddView((android.view.View)(mostCurrent._pdfv.getObject()),(int)(0),(int)(0),(int)(-1),(int)(-1));
^
1 error
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
That's the package name for IceFairy's pdf viewer library.
Actually it's the package name for the native java library that IceFairy's library wraps.
There's three files required for IceFairy's library:
  • b4aPdfViewer.jar
  • b4aPdfViewer.xml
  • PdfViewer.jar

PdfViewer.jar contains the cx.hell.android.lib.pagesview.PagesView class that is missing.

@gwapong Do you have all three of these files in your b4a additional libraries folder?

Martin.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
The emulator cannot access Windows file system.
You can embed the file inside the APK by adding it in the Files tab. It is then accessed with File.DirAssets.
The pdf reader will not be able to read an internal file. You will need to first copy the file from the assets folder to the storage card.

Sorry to continue this old thread.

I can not open a file in the directory of my application?

Are there any accessible directory to save the PDF and the adobe reader that can show?

Is it absolutely necessary to keep the PDF at sdcard?
 
Upvote 0
Top