PTPDFViewCtrl in Xamarin
PDFViewCtrl is a ViewGroup that can be embedded in any layout. It encapsulates a rich set of functionalities for interactive viewing of PDF documents, including multi-threaded rendering, PDF rendering settings, scrolling, zooming, page navigation, different page viewing modes, coordinates conversion, text selection, text search, etc.
View documents using PDFViewCtrl
In this tutorial you will display a PDF file in your activity by using PDFViewCtrl.
In your
AndroidManifest.xml, make sure you enablelargeHeapin the<application>tag. Also, add a custom theme and set theandroid:windowSoftInputMode:"adjustPan"attribute in the<activity>tag as follow:
<!-- Include existing attributes in application -->
<application android:name="androidx.multidex.MultiDexApplication" android:largeHeap="true" android:usesCleartextTraffic="false">
<!-- Include existing attributes in activity -->
<activity android:windowSoftInputMode="adjustPan" android:theme="@style/PDFTronAppTheme"/>
</application>If you would like to customize the appearance of the viewer activity, define
PDFTronAppThemefor your activity inres/values/styles.xml:You can learn more about this in the customize the viewer's theme guide.
<resources>
<style name="PDFTronAppTheme" parent="PDFTronAppThemeBase"> <item name="colorPrimary">#3F51B5</item> <item name="colorPrimaryDark">#303F9F</item> <item name="colorAccent">#FF4081</item> <!-- Action bar --> <item name="actionModeBackground">?attr/colorPrimary</item> <item name="windowActionModeOverlay">true</item> </style>
</resources>Now, add
PDFViewCtrlto your activity's XML layout. For example:
In your activity, get a reference to
PDFViewCtrlafter inflating the layout and callAppUtils.SetupPDFViewCtrl.
Next, choose a document to display by using the following options:Add a sample PDF to
src/main/res/rawfolder, then call:
View from resource
View from local device storage
Managing lifecycle
It is extremely important that you follow the Android activity/fragment lifecycle and clean up PDFViewCtrl and PDFDoc properly. Make sure you have the following in lifecycle callbacks:
Next steps
Want to annotate on PDF files in
PDFViewCtrl? Check out the Setup ToolManager guide.Want to display non-PDF files in
PDFViewCtrl? Check out the viewing other document types guide.
Last updated
Was this helpful?