Some test text!

keyboard_arrow_down

Get started

Download PDFTron SDK
play_arrow

Quick start - view a document

Xamarin.AndroidXamarin.iOSIntegrate with NuGetIntegrate manuallyAdd license keyPermissions (Android)Run samplesUpdate to latest version
keyboard_arrow_down

Xamarin.Forms

Document viewerBasic viewer
keyboard_arrow_down

Fundamentals

Java binding (Android)Objective-C binding (iOS)Code sharingDocument lockingDocument saving
keyboard_arrow_down

Document Viewer

play_arrow

Xamarin.Android

play_arrow

Xamarin.iOS

Show a document in a ViewControllerShow documents in a tabbed ViewControllerOpen from online URL
keyboard_arrow_down

Document Viewer components

Overview
play_arrow

PDFViewCtrl

Xamarin.AndroidXamarin.iOS
play_arrow

Reflow

Quick menuCustomize quick menu
play_arrow

Annotation toolbar

play_arrow

Annotation style editor

play_arrow

Page slider

play_arrow

List container

play_arrow

Annotation list

play_arrow

Document outline

play_arrow

User bookmark list

play_arrow

Thumbnail browser

Add pages dialogCrop pages dialogRotate pages dialogView mode dialog
keyboard_arrow_down

Annotation and collaboration

OverviewToolManager setupRead only mode
play_arrow

Disable annotation creation and editing

play_arrow

Default annotation properties

play_arrow

Change tool mode

Xamarin.AndroidXamarin.iOS
play_arrow

Events

Xamarin.AndroidXamarin.iOS
play_arrow

Override annotation handling

Show and hide existing annotationsRealtime collaboration
keyboard_arrow_down

Advanced customization

play_arrow

Add a custom view to a page

Create a custom toolPage color modePage fit modePage layout modeScrolling direction
keyboard_arrow_down

Conversion

keyboard_arrow_down

Parsing and extraction

keyboard_arrow_down

Digital signatures

keyboard_arrow_down

Form filling

keyboard_arrow_down

Search

keyboard_arrow_down

Redaction

keyboard_arrow_down

Advanced topics

PrintUnderstand coordinatesGenerate page thumbnails
keyboard_arrow_down

Reference

LocalizationIcon cheat sheet
keyboard_arrow_down

PDF Processing API

What is PDFNet?Opening a documentSerializing (saving) a documentWorking with pagesWorking with Page ContentWorking with BookmarksWorking with Interactive Forms (AcroForms)PDF SecurityLow-level PDF APIError handling
Document lockingkeyboard_arrow_down

Document locking

In this document
chevron_rightPDFDoc lock
chevron_rightLocking in the PDFTron API
chevron_rightClient side locking
chevron_rightFilters
chevron_rightMigration of earlier code
chevron_rightOpting out
chevron_rightAPI calls which can acquire a write lock
chevron_rightPDFViewCtrl

As computing devices become more parallel in nature, PDFTron is evolving to allow developers to leverage this power in new and exciting ways. PDFTron version 6.0 introduces new locking semantics which allow for concurrent access of a PDFDoc instance. This was done to improve performance during interactive viewing (simultaneous rendering, text extraction, etc.), as well as to open up the possibility for new use cases (parallel rendering). This article introduces the locking system, and will get you on your way to developing parallel applications with PDFTron SDK.

linkPDFDoc lock

PDFTron uses a recursive read/write locking system. Multiple threads can hold a read lock on the document, but only one thread can hold a write lock at any given time. A thread can acquire an equivalent or weaker lock as many times as it likes without causing a deadlock. In other words, the following is valid:

PDFDoc d = new PDFDoc("foo.pdf");
d.Lock();
d.Lock();
d.LockRead();

However, a thread cannot acquire a write lock while holding a read lock. Because one can only acquire a write lock when no read locks are held, this situation would inevitably lead to a deadlock. To avoid this scenario, PDFTron will throw a runtime exception whenever the situation occurs.

linkLocking in the PDFTron API

Some of our API calls internally acquire a write lock on the document. As a result, these calls can also throw a runtime exception if they are invoked while holding a read lock. This is noted in each method's documentation. Additionally, you will find a complete list of those methods at the end of this article.

In general, the parts of our library that manage the UI will maintain document locks. For the lower level calls which actually modify the document, you are responsible for maintaining document locks.

linkClient side locking

PDFTron provides the following APIs for locking the document:

void PDFDoc.Lock();
bool PDFDoc.TryLock(int milliseconds);
void PDFDoc.Unlock();
void PDFDoc.LockRead();
bool PDFDoc.TryLockRead(int milliseconds);
void PDFDoc.UnlockRead();

For convenience, PDFViewCtrl exposes similar methods, which will be applied to the document currently associated with the control. Additionally, the PDFViewCtrl.DocLock method takes a cancel_rendering parameter, which will interrupt all worker threads currently accessing the document. This allows you to acquire the write lock as fast as possible:

void PDFViewCtrl.DocLock(bool cancel_rendering);
bool PDFViewCtrl.DocTryLock(int milliseconds);
void PDFViewCtrl.DocUnlock();
void PDFViewCtrl.DocLockRead();
bool PDFViewCtrl.DocTryLockRead(int milliseconds);
void PDFViewCtrl.DocUnlockRead();

linkFilters

At the low level, a PDFDoc uses an input filter to access its PDF data. this data could be stored on the file system, in a memory buffer, or over a network. Now that PDFTron supports concurrent access of PDFDoc across many threads; these input filters must also be made thread-safe. StdFile, which was not a thread-safe filter, is no longer available. Instead, you should now use the new MappedFile filter, which provides thread-safe and efficient read access on a file. Custom user filters are still supported, although they are now wrapped in an internal filter that guarantees thread safety.

linkMigration of earlier code

The new locking system is backwards compatible, meaning previous calls to PDFDoc.Lock now acquire a write lock. If you would like to take advantage of the ability to read a PDF concurrently, it is your responsibility to review document locks and determine whether it is safe to downgrade them to a read lock.

linkOpting out

Conversely, if you are happy with the existing 'one document, one thread' model previously used in PDFTron 5.9., you can continue to work with this system. No change is required on your behalf.

linkAPI calls which can acquire a write lock

linkPDFViewCtrl

void PDFViewCtrl.CloseDoc();
void PDFViewCtrl.SetDoc(PDFDoc);