B4J Library [B4X] jPDFviewer

I would recommend PDFBox class an alternative. İts does not need jetty server. its more clear.
@knutf released new wrapper class for PDFBox from Apache.

Thank you @knutf gerat work.

https://www.b4x.com/android/forum/t...-show-pdf-document-in-b4j.103350/#post-647789

****************************************************


Hello everbody;

I was looking for a PDF viewer for a long time. I tried "http://viewerjs.org/", but I didn't get the result I wanted exactly. or I failed.
After I discovered PDF.js.
Finally I made a B4Xlib for PDF viewer. jPDFviewer library is based on github project.
I know... The method I use can be a little foolish. But its works. ;)

HAVE A FUN...

Source:

RELEASE NOT:
Version 1.3

  • adding zoom function on ShowPDF
  • pdf.js files are not embedded in the library.After that you can download the original files from GITHUB and use them in your project.
  • shared server (other views's properties must be false like under below )
upload_2019-2-20_13-39-57.png


jPDFviewer
Author:
Tayfur
Version: 1.3
  • jPDFviewer
    Methods:
    • Initialize (Callback As Object, EventName As String) As
    • DesignerCreateView (Base As Pane, Lbl As Label, Props As Map) As
    • ResetPDFsystem As
      its delete all logs and PDF files and reset PDF publisher
      log(jPDFviewer1.ResetPDFsystem)
    • GetBase As
    • LaodPDF (folderName As String, FileName As String) As Boolean
      its loading PDF file for acvtive publisher
      if jPDFviewer1.LaodPDF("C:\Users\PC1\Desktop\istanbul","citymap.pdf") Then
      jPDFviewer1.ShowPDF
      end if
    • ShowPDF (zoom As String) As
      its showing loaded PDF page
      zoom rate is : "page-width", "page-height", "page-fit", "auto","100","150" 150%
      jPDFviewer1.ShowPDF("")
    • Clear As
      its showing loaded PDF page
      jPDFviewer1.ShowPDF
    Properties:
    • ZipFile As
      get/set zip folder
      dafault folder is DirAsset
      jPDFviewer1.ZipFile="pdfjs-2.1.266-dist.zip" 'https://mozilla.github.io/pdf.js/
    • ZipFolder As
      get/set zip folder
      dafault folder is DirAsset
    • Viewpane As [read only]
      get node for PDF viewer
      Node=jPDFviewer1.node
    • ServerActive As
      get/set server manuel activate when you select false for "ServerAutoStart" section
      dont forget : if you want stop server, you should add "ExitApplication" on Form_closed event
      jPDFviewer1.Initialize(Me,"jPDFviewer1")
      jPDFviewer1.PDFpublisherLoacation=File.DirTemp
      jPDFviewer1.PDFpublisher="www"
      jPDFviewer1.ServerActive=true
    • PDFpublisher As
      get/set server manuel activate on location, Default is "www"
      jPDFviewer1.PDFpublisher="www"
    • Visible As
      get/set PDF viewer visible
      jPDFviewer1.Visible=true
    • PDFpublisherLoacation As
      get/set Publisher manuel activate on folder, Default is "File.DirTemp"
      jPDFviewer1.PDFpublisherLoacation=File.DirTemp
    Event:
    • GeneralError (Error As String)
    • PageShowed(PDFfile As String)
    • PageCleaned

    B4X:
    #Region Project Attributes
        #MainFormWidth: 600
        #MainFormHeight: 600
    #End Region
    
    Sub Process_Globals
        Private fx As JFX
        Private MainForm As Form
        Private Button1 As Button
        Private Button2 As Button
        Private jPDFviewer1 As jPDFviewer
        Private jPDFviewer2 As jPDFviewer
        Private jPDFviewerServer As jPDFviewer
        
        
    End Sub
    
    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        MainForm.RootPane.LoadLayout("L1")
         '*********************************************
         ' NOTE:
        ' jPDFviewer1 & 2 has in layout. Ant they "ServerActive" properties is FALSE
        ' We create manuelly jPDFviewerServer. And other viwer use same server.
        '*********************************************
        MainForm.Show
        
        jPDFviewerServer.Initialize(Me,"jPDFviewerServer")
        jPDFviewerServer.PDFpublisherLoacation=(File.DirTemp)
        jPDFviewerServer.PDFpublisher=("server")
        jPDFviewerServer.ZipFolder=File.DirAssets
        jPDFviewerServer.ZipFile="pdfjs-2.1.266-dist.zip" 'https://mozilla.github.io/pdf.js/
        Log(jPDFviewerServer.ResetPDFsystem)
        
        
        
    
        
        jPDFviewer1.PDFpublisherLoacation=(File.DirTemp)
        jPDFviewer1.PDFpublisher=("server")
        jPDFviewer2.PDFpublisherLoacation=(File.DirTemp    )
        jPDFviewer2.PDFpublisher=("server")
        
        
        
    End Sub
    
    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
        Return True
    End Sub
    
    Sub jPDFviewer1_GeneralError (Error As String)
        Log("jPDFviewer1_GeneralError"&Error)
    End Sub
    
    Sub jPDFviewer1_PageShowed(PDFfile As String)
        Log("jPDFviewer1_PageShowed:"&PDFfile)
    End Sub
    
    Sub jPDFviewer1_PageCleaned
        Log("jPDFviewer1_PageCleaned")
    End Sub
    
    Sub Button2_Click
        'jPDFviewer2.Clear
        jPDFviewer1.Clear
        jPDFviewer1.Visible=False
        Log(jPDFviewerServer.ResetPDFsystem)
    End Sub
    
    Sub Button1_Click
        jPDFviewer1.Visible=True
        If jPDFviewer1.LaodPDF("C:\Users\PC1\Desktop\VAN","MRK3753439.pdf") Then
            jPDFviewer1.ShowPDF("")
        End If
        
        If jPDFviewer2.LaodPDF("C:\Users\PC1\Desktop\VAN","MRK3753459.pdf") Then
            jPDFviewer2.ShowPDF("")
        End If
        
    
    End Sub
    
    Sub MainForm_Closed
        ExitApplication
        
    End Sub


  • ########################################
  • ########################################
  • ########################################

    jPDFviewer
    Author:
    Tayfur
    Version: 1
    • jPDFviewer
      Methods:
      • Initialize (Callback As Object, EventName As String) As
      • DesignerCreateView (Base As Pane, Lbl As Label, Props As Map) As
      • ResetPDFsystem As
        its delete all logs and reset publisher
        jPDFviewer1.ResetPDFsystem
      • GetBase As
      • LaodPDF (folderName As String, FileName As String) As Boolean
        its loading PDF file for acvtive publisher
        if jPDFviewer1.LaodPDF("C:\Users\PC1\Desktop\istanbul","citymap.pdf") Then
        jPDFviewer1.ShowPDF
        end if
      • ShowPDF As
        its showing loaded PDF page
        jPDFviewer1.ShowPDF
      • Clear As
        its showing loaded PDF page
        jPDFviewer1.ShowPDF
      Event:
      • GeneralError (Error As String)
      • PageShowed(PDFfile As String)
      • PageCleaned



      B4Xlib DOWNLOAD LINK : jPDFviewer (sorry size is 2,8bm)
 

Attachments

  • test-app-pdfviewer.zip
    123.4 KB · Views: 524
  • jPDFviewer2.zip
    4.9 KB · Views: 504
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User

Tayfur

Well-Known Member
Licensed User
Longtime User
It is the same code of your example
try this steps.
  • Download my test app. RUN it.
    1. Test app not run or same problem:
      • re-install jPDFviewer lib. And refresh library tab.
      • Delete "www" in "File.DirTEMP"
      • run again my app (try after close virus program)
    2. Test app is run
    • add your pdf file.
    • update my code for your pdf file name
    • run again test app
      1. Result is not OK >> send to me PDF file.
 

Tayfur

Well-Known Member
Licensed User
Longtime User
RELEASE NOT:
Version 1.3 (download: jPDFviewer2.zip)

  • adding zoom function on ShowPDF
  • pdf.js files are not embedded in the library.After that you can download the original files from GITHUB and use them in your project.
  • shared server (other views's properties must be false like picture first article )
 
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User
Top