A react native PDF view component for displaying PDF documents from various sources with caching support.
—
Core PDF rendering functionality providing support for multiple source types, caching, display configuration, and basic PDF interaction. This handles all aspects of loading and displaying PDF documents from various sources.
Configure PDF document sources from URLs, local files, base64 data, or bundled assets.
/**
* PDF source configuration
* Supports various source types: network URLs, local files, base64 data, bundled assets
*/
type Source = {
/** URL or file path to PDF document */
uri?: string;
/** HTTP headers for network requests (authentication, content-type, etc.) */
headers?: { [key: string]: string };
/** Enable caching for network PDFs to improve performance */
cache?: boolean;
/** Custom cache file name (defaults to SHA1 hash of URI) */
cacheFileName?: string;
/** Cache expiration time in days (defaults to no expiration) */
expiration?: number;
/** HTTP method for network requests (GET, POST, PUT, etc.) */
method?: string;
/** Request body for POST/PUT requests */
body?: string;
};Usage Examples:
// Network PDF with caching
const networkSource: Source = {
uri: "https://example.com/document.pdf",
cache: true,
cacheFileName: "my-document.pdf",
expiration: 7, // Cache for 7 days
headers: {
"Authorization": "Bearer token123"
}
};
// Local file
const localSource: Source = {
uri: "file:///path/to/document.pdf"
};
// Base64 encoded PDF
const base64Source: Source = {
uri: "data:application/pdf;base64,JVBERi0xLjQKMSAwIG9iago8PAovVHlwZS..."
};
// Bundled asset (using require)
const assetSource = require("./assets/document.pdf");
// Bundle assets (platform-specific)
const iOSBundleSource: Source = {
uri: "bundle-assets://document.pdf" // iOS only
};
const androidBundleSource: Source = {
uri: "bundle-assets://path/to/document.pdf" // Android only
};
// Content URI (Android)
const contentUriSource: Source = {
uri: "content://com.example.blobs/xxxxxxxx-...?offset=0&size=xxx"
};
// Blob URL (Android)
const blobSource: Source = {
uri: "blob:xxxxxxxx-...?offset=0&size=xxx"
};
// Windows app bundle
const windowsBundleSource: Source = {
uri: "ms-appx:///document.pdf" // Windows UWP only
};Configure PDF display properties including initial page, scaling, orientation, and layout.
/**
* Core display properties for PDF rendering
*/
interface DisplayProps {
/** PDF source configuration */
source: Source | number;
/** Initial page number to display (1-based, default: 1) */
page?: number;
/** Initial scale factor (default: 1.0) */
scale?: number;
/** Minimum allowed scale factor (default: 1.0) */
minScale?: number;
/** Maximum allowed scale factor (default: 3.0) */
maxScale?: number;
/** Enable horizontal scrolling mode (default: false - vertical) */
horizontal?: boolean;
/** Space between pages in pixels (default: 10) */
spacing?: number;
/** Display only single page at a time (default: false) */
singlePage?: boolean;
/** PDF password for encrypted documents */
password?: string;
/** Component style */
style?: ViewStyle;
}Control how PDF pages are initially sized to fit the viewport.
/**
* PDF fit policy configuration
* Controls initial zoom and page sizing behavior
*/
interface FitPolicyProps {
/**
* Fit policy for initial page sizing:
* 0 = fit width (page width matches container width)
* 1 = fit height (page height matches container height)
* 2 = fit both (page fits entirely within container, default)
*/
fitPolicy?: 0 | 1 | 2;
}Usage Examples:
// Fit to width - good for text documents
<Pdf
source={{ uri: "document.pdf" }}
fitPolicy={0}
style={{ flex: 1 }}
/>
// Fit to height - good for presentations
<Pdf
source={{ uri: "slides.pdf" }}
fitPolicy={1}
horizontal={true}
style={{ flex: 1 }}
/>
// Fit both (default) - shows entire page
<Pdf
source={{ uri: "document.pdf" }}
fitPolicy={2}
style={{ flex: 1 }}
/>Configure PDF rendering quality and features.
/**
* PDF rendering configuration
* Controls rendering quality and feature support
*/
interface RenderingProps {
/** Enable antialiasing for smoother text and graphics (default: true) */
enableAntialiasing?: boolean;
/** Enable PDF annotation rendering (default: true) */
enableAnnotationRendering?: boolean;
/** Trust all SSL certificates for HTTPS requests (default: true) */
trustAllCerts?: boolean;
}Support for bundled PDF assets using require().
/**
* Bundled asset support
* Use require() to bundle PDFs with your app
*/
type AssetSource = number; // Result of require('./path/to/pdf')Usage Example:
// Bundle PDF with your app
const bundledPdf = require("./assets/user-guide.pdf");
<Pdf
source={bundledPdf}
style={{ flex: 1 }}
/>Advanced networking and caching configuration for network PDFs.
/**
* Advanced network configuration
* For complex authentication and request scenarios
*/
interface AdvancedSourceConfig {
/** Full source configuration */
source: {
uri: string;
/** Custom HTTP headers */
headers?: {
"Authorization"?: string;
"User-Agent"?: string;
"Content-Type"?: string;
[key: string]: string;
};
/** HTTP method */
method?: "GET" | "POST" | "PUT" | "PATCH";
/** Request body for POST/PUT */
body?: string;
/** Cache configuration */
cache?: boolean;
cacheFileName?: string;
expiration?: number;
};
}Usage Example:
// Complex network configuration
<Pdf
source={{
uri: "https://api.example.com/documents/123",
method: "POST",
headers: {
"Authorization": "Bearer " + accessToken,
"Content-Type": "application/json"
},
body: JSON.stringify({ format: "pdf", quality: "high" }),
cache: true,
expiration: 1 // Cache for 1 day
}}
style={{ flex: 1 }}
/>Install with Tessl CLI
npx tessl i tessl/npm-react-native-pdf