DocViewer.Android
3.0.8
dotnet add package DocViewer.Android --version 3.0.8
NuGet\Install-Package DocViewer.Android -Version 3.0.8
<PackageReference Include="DocViewer.Android" Version="3.0.8" />
<PackageVersion Include="DocViewer.Android" Version="3.0.8" />
<PackageReference Include="DocViewer.Android" />
paket add DocViewer.Android --version 3.0.8
#r "nuget: DocViewer.Android, 3.0.8"
#:package DocViewer.Android@3.0.8
#addin nuget:?package=DocViewer.Android&version=3.0.8
#tool nuget:?package=DocViewer.Android&version=3.0.8
PdfViewer for .NET Android
A robust .NET for Android binding library for the Pdf-Viewer library. This library provides a feature-rich, customizable PDF viewer component for Xamarin.Android and .NET Android applications.
Features
- Multiple Loading Sources: Load PDFs from URL, File, Assets, or URI.
- Advanced Navigation: Horizontal/Vertical scrolling, Single Page mode, Wrapped mode.
- Page Layout: Spread modes (Odd/Even), Page Snapping, Single Page Arrangement.
- Complete UI System: Includes
PdfToolBar,PdfScrollBar, andPdfViewerContainerfor a drop-in UI. - Editor Capabilities: Built-in support for basic annotation actions (Undo/Redo) and property customization.
- Customizable: Extensive API to control visual properties and alignment.
- Zero Warnings: Clean build with no binding warnings.
Installation
Add the PdfViewer.Binding project or DLL to your .NET Android solution.
- Add
PdfViewer.Binding.csprojto your solution. - Add a project reference from your App project to
PdfViewer.Binding.
Getting Started
1. XML Layout
The library provides a composed UI container PdfViewerContainer that automatically manages the Viewer, Toolbar, and ScrollBar.
<com.bhuvaneshw.pdf.ui.PdfViewerContainer
android:id="@+id/pdfViewerContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.bhuvaneshw.pdf.ui.PdfToolBar
android:id="@+id/pdfToolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.bhuvaneshw.pdf.PdfViewer
android:id="@+id/pdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.bhuvaneshw.pdf.ui.PdfScrollBar
android:id="@+id/pdfScrollBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.bhuvaneshw.pdf.ui.PdfViewerContainer>
2. Basic Initialization (C#)
In your Activity or Fragment:
using Com.Bhuvaneshw.Pdf;
using Com.Bhuvaneshw.Pdf.UI;
// ... Inside OnCreate
// 1. Find References
var viewer = FindViewById<PdfViewer>(Resource.Id.pdfViewer);
var container = FindViewById<PdfViewerContainer>(Resource.Id.pdfViewerContainer);
var toolbar = FindViewById<PdfToolBar>(Resource.Id.pdfToolBar);
var scrollBar = FindViewById<PdfScrollBar>(Resource.Id.pdfScrollBar);
// 2. Setup Dependencies
toolbar.SetupWith(viewer);
scrollBar.SetupWith(viewer, toolbar, false); // false = force update
// 3. Load PDF
viewer.LoadFromUrl("https://example.com/sample.pdf");
// OR
// viewer.LoadFromAsset("sample.pdf");
detailed API Reference
Loading Content
| Method | Description |
|---|---|
LoadFromUrl(string url) |
Loads a PDF from a remote URL. |
LoadFromAsset(string assetName) |
Loads a PDF from the application's Assets folder. |
LoadFromFile(File file) |
Loads a PDF from a local Java.IO.File. |
LoadFromFileUri(Uri uri) |
Loads a PDF from an Android Uri. |
Configuration Properties
The PdfViewer class exposes several properties to control behavior and appearance.
Scroll Mode (PdfViewer.ScrollMode)
Controls how pages are scrolled.
PageScrollMode.Horizontal: Standard horizontal scrolling.PageScrollMode.Vertical: Standard vertical scrolling (Default).PageScrollMode.SinglePage: Displays one page at a time.PageScrollMode.Wrapped: Wraps pages like a continuous document.
viewer.ScrollMode = PdfViewer.PageScrollMode.Horizontal;
Spread Mode (PdfViewer.SpreadMode)
Controls page spreads (like a book view).
PageSpreadMode.None: Single page view (Default).PageSpreadMode.Odd: Starts with an odd page.PageSpreadMode.Even: Starts with an even page.
viewer.SpreadMode = PdfViewer.PageSpreadMode.Odd;
Align Mode (PdfViewer.AlignMode)
Controls page alignment within the viewport.
PageAlignMode.StartPageAlignMode.CenterHorizontalPageAlignMode.CenterVerticalPageAlignMode.CenterBoth- etc.
viewer.AlignMode = PdfViewer.PageAlignMode.CenterBoth;
Other Properties
SnapPage(bool): If true, scrolling snaps to the nearest page edge.SinglePageArrangement(bool): Optimized arrangement for single page viewing.PageRotation(int): Rotation angle in degrees (0, 90, 180, 270).DoubleClickThreshold(long): Time in ms for detecting double clicks.LongClickThreshold(long): Time in ms for detecting long clicks.ScrollSpeedLimit(float): Max scroll speed multiplier.
PdfToolBar Customization
The PdfToolBar provides built-in navigation and actions.
Handling Back Button: Because
OnBackexpects a Kotlin function, use a helper class implementation:private class BackAction : Java.Lang.Object, Kotlin.Jvm.Functions.IFunction0 { private readonly Activity _act; public BackAction(Activity a) => _act = a; public Java.Lang.Object Invoke() { _act.Finish(); return null; } } toolbar.OnBack = new BackAction(this);
PdfEditor
Access annotation features via the Editor property.
// Undo/Redo
viewer.Editor.Undo();
viewer.Editor.Redo();
// Customization
viewer.Editor.HighlightColor = Android.Graphics.Color.Yellow;
viewer.Editor.InkColor = Android.Graphics.Color.Red;
Requirements
- .NET 10 Android
- Android SDK 23+ (Min SDK)
Build Instructions
cd PdfViewer.Binding
dotnet build
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-android36.0 is compatible. |
-
net10.0-android36.0
- Xamarin.AndroidX.ConstraintLayout (>= 2.2.1.3)
- Xamarin.AndroidX.WebKit (>= 1.14.0.1)
- Xamarin.Google.Android.Material (>= 1.13.0)
- Xamarin.Kotlin.StdLib (>= 2.2.21)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.8 | 449 | 12/11/2025 |