[free lib]b4aPDFViewer by Icefairy333

icefairy333

Active Member
Licensed User
Longtime User
[free lib]b4aPDFViewer by Icefairy333

Now you can show pdf in B4A!:D
limit:support arm cpu only(because jni include)
support both English and Chinese.android2.2-android4.0(havn't test 4.1 or 4.2)
here is the example code:
B4X:
#Region  Project Attributes
   #ApplicationLabel: B4A PdfViewer
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: portrait
   #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim pdfv As PDFViewer
   Dim i,pc As Int=0
   Dim iv
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   pdfv.init
   Activity.AddView(pdfv,0,0,-1,-1)
   pdfv.getpdf(File.DirRootExternal&"/t.pdf")
   If pdfv.isValid Then
      'Log("pagecount:"&pdfv.PageCount)
      pdfv.scrollToPage(0)
      pc=pdfv.GetPageCount
      pdfv.zoom(3.0)
  
   Else
      Msgbox("Error pdf file!","Error")
      Activity.Finish
      Return
   End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
b4aPdfViewer
Author:
Icefairy333
Version: 1.12
  • PDFViewer
    Methods:
    • BringToFront
    • GetPageCount As Int
    • Initialize (arg1 As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • finalize
    • findOnPage (str As String, pageid As Int) As Int
    • getPageBitmap (page As Int, zoom As Int, x As Int, y As Int, rotation As Int, prefXSize As Int, prefYSize As Int) As Bitmap
    • getpdf (filepath As String)
      you can't load pdf from assets dir
    • getpdf2 (filepath As String, password As String)
    • init

      volControl: if the vol button control pagedown or pageup
    • isValid As Boolean
    • scrollToFindResult (n As Int)
    • scrollToPage (page As Int)
    • zoom (value As Float)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
here is the screen capture:
15931d1360741770-lib-b4apdfviewer-icefairy333-1.jpg
attachment.php
attachment.php
attachment.php

download the library:
 

Attachments

  • 1.jpg
    1.jpg
    27 KB · Views: 1,630
  • 2.jpg
    2.jpg
    27.7 KB · Views: 2,993
  • 3.jpg
    3.jpg
    28.2 KB · Views: 2,970
  • 4.jpg
    4.jpg
    79 KB · Views: 3,025
Last edited by a moderator:

Harris

Expert
Licensed User
Longtime User
using your example

Parsing code. 0.00
Compiling code. Error
Error compiling program.
Error description: Object reference not set to an instance of an object.
Occurred on line: 35
pdfv.init("")
Word: (


then using: pdfv.init - it will compile...

Added my own t.pdf file (a real.pdf)

Can't figure further error. Supplied my test project.

Suggestion: Supply example that will compile and is tested - like most others.

Looks hopeful! However - simple apk is 3.5 meg...

Tried on OS 2.3
 

Attachments

  • pdfview.zip
    21.4 KB · Views: 1,436

icefairy333

Active Member
Licensed User
Longtime User
sorry I changed the init method;

Parsing code. 0.00
Compiling code. Error
Error compiling program.
Error description: Object reference not set to an instance of an object.
Occurred on line: 35
pdfv.init("")
Word: (


then using: pdfv.init - it will compile...

Added my own t.pdf file (a real.pdf)

Can't figure further error. Supplied my test project.

Suggestion: Supply example that will compile and is tested - like most others.

Looks hopeful! However - simple apk is 3.5 meg...

Tried on OS 2.3
 

fanfalveto

Active Member
Licensed User
Longtime User
Very good job,thank you.
Sure i`m doing something wrong but zoom not works fine
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    pdfv.init
Activity.AddView(pdfv,0,0,-1,-1)
    pdfv.getpdf(File.DirRootExternal&"/Scale.pdf")
   zoom=1
    pdfv.scrollToPage(0)
        pc=pdfv.GetPageCount
        pdfv.zoom(zoom)

   
   Activity.AddMenuItem("Zoom +","mas")
   Activity.AddMenuItem("Zoom -","menos")
End Sub

Sub mas_Click
   zoom=zoom+0.5
   Log ("nuevo zoom + "&zoom)
    pdfv.zoom(zoom)
End Sub
Sub menos_Click

   zoom=zoom-0.5
   Log ("nuevo zoom - "&zoom)
   

        pdfv.zoom(zoom)
 
End Sub
:sign0085:
 

Valserwasser

New Member
Licensed User
Longtime User
getPageBitmap

Hi

Thanks for this library.
Could you please explain how to use the getPageBitmap?
Anyway... it would be very helpful if you would add an example covering all the features.

Thank you!
 

fatman

Active Member
Licensed User
Longtime User
Hi Icefairy333,

i tried to download your lib but failded. When i click on the link (baidu net disk) the text presented there is not in english but in asian letters.
What do i have to do?

Thx Fatman
 
Last edited:
Top