PDF viewer: navigation, selection and editable objects
The pdfBoxWrapper B4J component is a viewer and overlay editor. Create it with the Designer or call Initialize and add it to a Pane.
Example: load and navigate
' Requires an existing Pane named ContainerPane.
Dim viewer As pdfBoxWrapper
viewer.Initialize(Me, "Viewer")
viewer.AddToParent(ContainerPane, 0, 0, 900, 600)
Dim path As String = File.Combine(File.DirApp, "contract.pdf")
If viewer.loadDocument(path, 1.0) Then
Log("Pages: " & viewer.getNumberOfPages)
viewer.ScrollToPage(0)
viewer.Repaint(1.25)
Else
Log("Could not load PDF")
End If
Use case: preview and browse agreements, document packages and submitted files.
Multiple documents
Use OpenDocuments(Paths, Zoom), GetDocuments, SelectDocument(index), CloseActiveDocument and CloseAllDocuments. Indexes are zero-based.
Caution: check HasEditableObjects before changing or closing documents, and explicitly save or discard edits. Do not assume changing tabs persists annotations.
Persisting editable overlays
FlattenObjectsToPDF(DocumentPath) asks your host application to burn editable objects into a PDF. Your callback is responsible for writing the objects.
Viewer_BurnObject(Data As TBurnObjectData): legacy event, without guaranteed acknowledgement.Viewer_BurnObjectConfirmed(Data As TBurnObjectData, ObjectID As String) As Boolean: optional callback. ReturnTrueonly after the write has actually completed.ResolveFlattenPersistence(Persisted As Boolean, AllWritesRolledBack As Boolean): resolve uncertain states only after verifying or fully rolling back writes.getLastFlattenSucceeded: read the reported persistence status.
Never return True before a real write. After partial failures, check the output before retrying to prevent duplicate objects.
StartSelection / CancelSelection handle area selection. PlaceSignature(img As Image) and GetSignaturePosition() can help users select a visible stamp position. These are not substitutes for a cryptographic signature: call SignPDF or SignPDFVisible to actually sign.