iOS Question PDF support

pacpinto

Member
Licensed User
Hi,

Is there anything at all similar to this library https://www.b4x.com/android/forum/threads/pdfium-pdfview2.102756/#content for B4i? I know I can open PDFs using a WebView, and that I can build a viewer of sorts using the PDFDocument object. However, using the WebView I can't get lateral swipe to change pages, or a thumbnail view; and using PDFDocument to extract bitmaps leaves a lot of PDF functionality behind - links, for example.

Thanks in advance!
 

pacpinto

Member
Licensed User
Somehow I tried it. To build simple viewer requires some statements only.
There are delegate functions. Not very powerful, but are able, for example, to handle clicks on URL links.

Hi, and thank you for your reply! Could you show me how to build a simple viewer using PDFKit? I was aware of this framework but I don't know how to use it from B4i.
Thank you once again!
 
Upvote 0

pacpinto

Member
Licensed User
I reduced PDF-file due to forum's limitations.
Can't say that this is a sample. Simply first steps.
I was able to do exactly what I wanted. The only missing piece is, I want to respond to a click/touch event on the pdf, in order to show thumbnails, allow search function, etc. Do you know how to do this? Only need the "hook" for the event... thank you once again, your help is much appreciated.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I imagine how to do this. There are some experiments in attached file.
A documentation talks about "notifications".

To handle the notifications, you need to set the observers. Of course, not all, but needed only. For example, you want to monitor 'selections'.
B4X:
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (_pdfviewselectionchangednotification)    name: PDFViewSelectionChangedNotification    object: nil];

Then you can process in B4i subroutine. Example
B4X:
Private Sub PDFViewSelectionChangedNotification ' A notification posted when the current selection has changed.
   
    Dim nativeObjectCurrentSelection                                   As NativeObject
   
    nativeObjectCurrentSelection = nativeObjectPDFView.GetField ("currentSelection")
    If nativeObjectCurrentSelection.IsInitialized Then
        Log ("PDFViewSelectionChangedNotification: Current Selection = " & nativeObjectCurrentSelection.GetField ("string").AsString)
    Else
        Log ("PDFViewSelectionChangedNotification: Not selected")
    End If
                 
End Sub
 

Attachments

  • test.zip
    401.4 KB · Views: 351
Last edited:
Upvote 0

pacpinto

Member
Licensed User
I imagine how to do this. There are some experiments in attached file.
Thank you so much. I'm new to this tool and have been struggling with the documentation. Practical examples like these are far easier to understand. So once again, thank you both for your help and for making it accessible.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
About links. If you want to prevent standard reaction, you can use a delegate (in addition to Notifications).

Documentation https://developer.apple.com/documentation/pdfkit/pdfviewdelegate?language=objc talks that a delegate supports PDFViewWillClickOnLink:withURL: method, which handle clicks on URL links in a PDFView.

So, we add
1)
B4X:
nativeObjectPDFView.SetField ("delegate", Me)

2) A subroutine, which will receive 'clicked' url:
B4X:
Sub PDFViewWillClickOnLink (PDFViewSender As Object, stringURL As String)
       Log ("Clicked: " & stringURL)
End Sub

3) In OBJC we redirect to B4i subroutine
B4X:
- (void) PDFViewWillClickOnLink: (PDFView *) sender withURL: (NSURL *) url  {  [self _pdfviewwillclickonlink: sender : url.absoluteString];  }

I updated test.zip
 
Upvote 0

stevenindon

Active Member
Licensed User
Hello,

I have downloaded the test.zip by Semen Matusovskiy (Great Job!)... and it is just exactly a PDF viewer that i want.
I need to create 2 addditional things :

1) buttons to jump page - example PDFView.Jumppage(2)
2) a label for total page count and current page

I have seen the codes and couldnt find any function that indicated jump page / total pdf page / Current page No. Please help.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
I'm struggling to use this approach and open a PDF file that is protected (has a password to view). Can someone point me in the right direction?

James
 
Upvote 0
Top