Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a customizable PDF preview inside a JavaScript application, start with Mozilla PDF.js, distributed on npm as pdfjs-dist. Choose its full viewer when you need an existing reading interface to adapt, or its display layer when you want to build your own. Before loading a PDF from a URL, check whether your app can serve it under the browser’s origin rules; alternatively, PDF.js documents loading binary data as a Uint8Array.

Choose the right PDF.js layer

PDF.js is an HTML5 PDF viewer project supported by Mozilla. Its npm distribution is named pdfjs-dist. The project separates PDF processing into core, display, and viewer layers. The display layer exposes an API; the viewer is a user interface built on that layer.

Use the viewer when you need a starting interface

The full viewer is the quickest route when your application needs a conventional PDF-reading experience and its existing interface is close to what you want. You can open documents through the viewer’s file URL parameter or through the viewer application API. The viewer also documents URL controls for opening at a page, setting zoom, navigating to a named destination, and choosing a sidebar mode.

Mozilla asks developers embedding the viewer not to use it as an unmodified copy. Treat it as a starting point: adapt its interface to your product rather than presenting an untouched copy as your own application.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the display layer for a tailored experience

If you need to control the surrounding interface or build a custom preview, work with the display layer rather than adopting the full viewer UI. This gives your application the display API while leaving interface decisions to you. That route gives more control, but it also means your application—not a pre-existing full viewer interface—must provide the experience you need.

Decide how the PDF reaches the browser

There are two useful ways to think about document input: a URL that the browser-based viewer can fetch, or binary data supplied to PDF.js. The right choice depends on how your application obtains the file and whether the browser can access it.

Loading a PDF by URL

The viewer documents a file URL parameter for selecting a PDF. This is convenient when a document is available at a URL your application can load. But a URL alone does not guarantee that loading will work: PDF.js documentation calls out same-origin restrictions. Check the origin relationship between your application and the PDF host, along with the serving and cross-origin configuration, before treating a remote URL as a viable input.

Do not diagnose every failed remote preview as a rendering problem. First establish whether the PDF can be fetched in the browser under the current origin and server setup. The available documentation identifies origin restrictions as a relevant constraint, but does not establish a server-specific CORS configuration; the correct setup depends on how your application and document host are deployed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Passing binary data

When your application already has the document bytes, PDF.js’s FAQ documents passing binary data as a Uint8Array. This can avoid relying on the viewer to fetch a remote PDF URL, but it does not remove the need to obtain the document successfully in the first place. Choose this route when your existing application flow provides the bytes and your integration is built around the display API.

Plan the preview before implementing it

There is no single best integration for every JavaScript application. Make these choices first so you do not build a custom interface when the viewer would have worked—or adopt a viewer UI that conflicts with your product.

  • How much UI customization do you need? Start with the viewer if its interface is a useful base. Use the display layer if you need a tailored interface.
  • How do you obtain the PDF? Decide whether the viewer can fetch a URL or whether your application will supply binary data as a Uint8Array.
  • Can the browser access the document? Verify the origin and serving setup for URL-based loading before investing time in viewer changes.
  • What navigation should the preview support? The viewer documentation describes controls for page, zoom, named destination, and sidebar mode. Confirm the behavior you need in the version you deploy.

PDF.js’s current release number, browser-by-browser compatibility, and a complete integration example are not established here. Check the project’s current package documentation and the code for the version you select before shipping; do not assume that an option documented in older viewer guidance behaves identically in every current release.

Viewer controls and customization

The viewer’s documented URL controls cover four distinct needs: opening a particular page, choosing a zoom level, navigating to a named destination, and selecting a sidebar mode. These controls are useful when you want a link to open a document at a particular reading context rather than always at its default view.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The documentation for viewer options was last edited in 2019, so treat it as a reference for the documented option names, not as proof of current behavior in every release. Verify any control you rely on against the viewer version you deploy. If your application needs a different presentation or navigation model, the display layer is the more appropriate place to build a tailored experience.

Performance and reliability considerations

For a remote PDF, the first reliability question is whether the browser can retrieve it under the application’s origin and server configuration. Resolve that before investigating display behavior. If you already have binary data, PDF.js’s documented Uint8Array input is another way to supply the document.

The PDF.js FAQ raises whether the default viewer can fetch only the portions needed to render visible pages. The available material does not establish when partial fetching occurs or its performance impact, so do not promise faster loading or lower transfer use on that basis. Measure the behavior with your own documents and deployment if those characteristics matter to your application.

No supported benchmark, universal load-time figure, or browser compatibility matrix is established here. PDF size, delivery path, server configuration, and the viewer version are all relevant to an implementation; test with the actual documents and hosting arrangement you expect to support.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Other embedded-viewer option

PDF.js Express describes a free in-browser viewer and a commercial Plus offering that can be embedded in JavaScript applications. The available product information does not establish current pricing, licensing details, feature limits, or affiliate terms. If you evaluate it, verify those terms and the capabilities your application needs directly with the vendor rather than assuming the free and commercial offerings have interchangeable limits.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a PDF viewer: it captures a webpage as an image or PDF and does not replace PDF.js for displaying a PDF document in an application. It may help when what you need is a capture of an HTML page rather than an interactive PDF preview. See the ScreenshotNeo API documentation.

For example, this cURL request captures a webpage as a WebP image:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Before capture, ScreenshotNeo accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sign up free for 1,000 screenshots a month with no card.

Troubleshooting a PDF preview

The viewer does not load a PDF from its URL

Check whether the document is accessible to the browser from your application’s origin and review the document host’s serving and cross-origin setup. The PDF.js documentation flags same-origin restrictions; a viewer option cannot by itself make an inaccessible URL fetchable.

You need to show a PDF your application already received

Use the documented binary-data route: PDF.js’s FAQ describes passing the bytes as a Uint8Array. Confirm that your chosen integration layer accepts the data in the way your deployed version expects.

A viewer URL control has no effect

Confirm the control is supported by the viewer version you actually use. The viewer-options documentation was last edited in 2019; its documented page, zoom, named-destination, and sidebar controls should be checked against current behavior rather than assumed to be release-independent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You need a different interface from the supplied viewer

Use the display layer to build a tailored interface, or adapt the viewer rather than embedding an unmodified copy. The choice depends on how much of the viewer UI you can retain.

Frequently asked questions

Is PDF.js the same thing as pdfjs-dist?

PDF.js is the project; pdfjs-dist is its npm distribution.

Can ScreenshotNeo preview a PDF inside my JavaScript application?

No. ScreenshotNeo captures webpages; use PDF.js when you need an in-app PDF viewer. ScreenshotNeo’s capture_pdf MCP tool is for capturing a webpage as a PDF, not for rendering an existing PDF in an application.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.