iOS Question PDF and WebView

Moosi

Member
Licensed User
Longtime User
Sure, its easy.

B4X:
If File.Exists(File.DirLibrary, "help.pdf") Then
   WebView1.LoadUrl(File.DirLibrary&"/"&"help.pdf")
End If
 
Upvote 0

drponciano

Member
Licensed User
Longtime User
Thanks very much for your help:

I have tried this:
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title ="Hola"
Page1.RootPanel.Color = Colors.Gray
NavControl.ShowPage(Page1)
webview1.Initialize("eventoweb")
webview1.LoadUrl("file://" & File.Combine(File.DirAssets, "example.pdf"))
end sub

Pagefinished returns a success but I never see th PDF file on screen, just the grey color and "hola" text. Any idea?
 
Upvote 0

Moosi

Member
Licensed User
Longtime User
Try it without the "file://" and use File.DirLibrary.
File.DirAssets will not work
B4X:
WebView1.LoadUrl(File.DirLibrary&"/"&"example.pdf")

And please use the CODE Tags for your code in the Forum. It is much easier to read :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Perhaps JetPDF has been ported to B4i then you can check out that as well as an alternative solution. Cheers, Roger
 
Upvote 0

drponciano

Member
Licensed User
Longtime User
I have used "webview1.LoadUrl("file://" & File.Combine(File.DirDocuments, "example.pdf"))". I know the file is there, and webview pagefinished for the event reports TRUE for the URL (I have used loadurl("http://www.google.com") or file but tho contents are not shown on the device.
 
Upvote 0

Moosi

Member
Licensed User
Longtime User
Have you tested to put your File in the "Files" folder and then called:
B4X:
WebView1.LoadUrl(File.DirLibrary&"/"&"example.pdf")
?

Don´t make your life harder than it is. Don´t use
B4X:
"file://" & File.Combine
 
Upvote 0

drponciano

Member
Licensed User
Longtime User
Super simple code to visualize a PDF file but... I never see the document on screen! What is wrong?

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private ScrollView1 As ScrollView
    Private cvsPDF As Canvas
    Private webview1 As WebView

End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title ="Hola"
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    createpdf
    webview1.Initialize("eventoweb")
'    webview1.Visible=True
'    webview1.ScaleToFit=True
'    webview1.SetBorder(2,Colors.Red,2)
    Log("Display document")
    webview1.LoadUrl("file://" & File.Combine(File.DirLibrary, "mipdf.pdf"))
   
End Sub


Sub Delay(nMilliSecond As Long)
Dim nBeginTime As Long
Dim nEndTime As Long
nEndTime = DateTime.Now + nMilliSecond
nBeginTime = DateTime.Now
Do While nBeginTime < nEndTime
nBeginTime = DateTime.Now
'Log(nBeginTime)
If nEndTime < nBeginTime Then
Return
End If
'DoEvents
Loop
End Sub

Sub eventoweb_PageFinished (Success As Boolean, Url As String)
   Log("Cargado "&Success&"   " & Url)
    Dim no As NativeObject = webview1
    Delay(2000)
    Log("Despues de delay")
    no.RunMethod("stringByEvaluatingJavaScriptFromString:", Array("window.scroll(0,500)"))
   
End Sub


Sub createpdf
    Log("Creapdf")
    ' 612x792 es la resolución estándar de los documentos PDF
    cvsPDF.InitializePDF(File.DirLibrary,"mipdf.pdf",612,792)
    cvsPDF.DrawLine(0,0,500,500,Colors.Red,2)
    cvsPDF.DrawLine(500,0,0,500,Colors.Green,0.5)
    cvsPDF.Release   
End Sub

Private Sub Application_Background
   
End Sub
 
Upvote 0

drponciano

Member
Licensed User
Longtime User
CreatePDF sub creates the PDF and saves to dirlibrary. I've tried with DirDocuments. DirAssets with same results. Pagefinished result is Success=true. I removed the delay, still not viewing the document. If I use PDFDocument I can see the document but I need Zoom and Pan. Thanks for your help Erel.
 
Upvote 0

drponciano

Member
Licensed User
Longtime User
I have tried with files in file.dirdocuments, dirassets, dirlibrary with same results. I have also tried loading from URL like webview1.loadfromurl("http:""www.google.com"), with and whout the no.runmethod... Pgefinished return true so I assume files and URL are read but no displayed. Thanks for your help.
 

Attachments

  • PDFReaderWebView.zip
    203.5 KB · Views: 347
Upvote 0

drponciano

Member
Licensed User
Longtime User
Problem solved! Thanks Erel. I had used view initialization before without problems so this was a surprise for me. Thanks again. :)
 
Upvote 0
Top