Pdf Viewer Apis
Functions to open PDF files in a native, in-app viewer instead of downloading them or handing them off to an external app.
The WebToNative PDF Viewer plugin renders the file natively — search, thumbnails, password-protected files, download, and share are all handled in-app.
You'll need to import the javascript file in your website before starting from this link.
Platform support: Android and iOS.
Setting Up PDF Viewer
Go to your WebToNative dashboard → Add-ons → PDF Viewer and enable it.
Configure the toolbar/behavior options you want under the same add-on page:
Toolbar Title
toolbarTitle
(uses the title passed from JS)
Overrides the title argument if set to a non-blank value.
Show Download
showDownload
Off
Shows a download-to-device button in the toolbar.
Show Share
showShare
Off
Shows a share-sheet button in the toolbar.
Show Search
showSearch
Off
Shows an in-document search button.
Show Thumbnails
showThumbnails
Off
Shows a page-thumbnail grid button.
Show Page Indicator
showPageIndicator
Off on Android, On on iOS ⚠
Shows a page-number pill at the bottom. See the platform-difference hint below.
Auto-Detect PDF Links
autoDetectLinks
Off
If a link the user taps inside your site resolves to a .pdf URL, opens it in the native viewer instead of navigating the WebView. See Auto-Detect Matching below.
URL Patterns
urlPatterns
(empty)
Only used when Auto-Detect is on — see below.
Error Message
errorMessage
(native default message)
Custom text shown if a PDF fails to load.
Error Button Text
errorButtonName
"Retry"
Label for the retry button on the error screen.
showPageIndicator defaults differently per platform when left unset. Android hides the page indicator by default; iOS shows it by default. If you need identical behavior on both platforms, set this explicitly in the dashboard rather than relying on the default.
JavaScript API Reference
openPDF
Opens a PDF from a URL in the native in-app viewer.
Parameters:
url
String
Yes
The URL of the PDF to open. Throws a JavaScript error immediately (before reaching native code) if blank.
title
String
No
Shown in the viewer's toolbar, unless the dashboard's Toolbar Title field is set to a non-blank value, which takes priority.
openPDF has no callback parameter. All viewer configuration (search, thumbnails, password handling, download, share, auto-detect) comes from the dashboard settings above, not from additional arguments to this call — there is nothing else to pass here beyond url and title.
Auto-Detect Matching Differs By Platform
If you enable Auto-Detect PDF Links, the matching rule against urlPatterns is not identical on both platforms:
Android opens the viewer for any URL simply ending in
.pdf.urlPatternsis only consulted as a fallback for URLs that don't end in.pdf(substring match).iOS requires the URL to both end in
.pdfand match at least one entry inurlPatternsas a prefix. A bare.pdfURL with Auto-Detect on and nourlPatternsconfigured will open automatically on Android but not on iOS.
If you need consistent behavior, always fill in urlPatterns explicitly rather than relying on the "any .pdf URL" fallback that only exists on Android.
Frequently Asked Questions
Last updated