Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To show PDF.js controls inside Fancybox 3, make the iframe load PDF.js’s viewer.html page and pass the PDF’s URL in its file parameter. Pointing Fancybox straight at a .pdf file may show the browser’s built-in PDF display, but it does not turn that file into a PDF.js viewer.
Why opening the PDF directly is not enough
Fancybox 3 supplies the modal and iframe. PDF.js supplies the application that parses and displays the document, including its viewer controls. The intended arrangement is:
Fancybox modal → iframe → PDF.js viewer.html → PDF file
This markup embeds a PDF resource, not the PDF.js application:
Free tools Windows power users keep installed
One-click scans. No signup required.
<a data-fancybox data-type="iframe"
data-f251e-parked-src="/documents/brochure.pdf" href="#">
View brochure
</a>
What appears may depend on the browser’s native PDF handling, and it will not reliably provide PDF.js’s toolbar. Fancybox 3’s documentation demonstrates the distinction by using an iframe pointed at PDF.js viewer.html for its PDF example. Fancybox 3 documentation
#1 Best Overall
- CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
- WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
- A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
Minimal local setup
Deploy a compatible PDF.js viewer build with your application, keeping its viewer, worker, and related assets together. The example assumes the viewer is available at /pdfjs/web/viewer.html and the document at /documents/brochure.pdf. Use the paths that match your deployment.
<link rel="stylesheet" href="/vendor/jquery.fancybox.min.css">
<a data-fancybox
data-type="iframe"
data-f251e-parked-src="/pdfjs/web/viewer.html?file=%2Fdocuments%2Fbrochure.pdf"
href="/documents/brochure.pdf"
aria-label="Open brochure in PDF viewer">
View brochure
</a>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="/vendor/jquery.fancybox.min.js"></script>
<script>
$('[data-fancybox]').fancybox({
iframe: { preload: false },
toolbar: false,
smallBtn: true
});
</script>
Load jQuery before Fancybox, as Fancybox 3’s setup documentation specifies. The exact jQuery/Fancybox combination should be tested in the application; this is a legacy jQuery integration, not a guarantee about every modern stack. The link’s href remains the actual PDF as a useful fallback, while data-src tells Fancybox to display the viewer. Avoid using javascript:; as the only link destination.
Fancybox 3’s iframe settings document preload behavior and same-origin limitations. Setting preload: false avoids relying on Fancybox to inspect and size a full viewer application inside the iframe. Fancybox 3 iframe documentation
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #2
- CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
- 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
- SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
- INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
- THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
Build the viewer URL safely
The PDF URL belongs inside the viewer’s file query parameter. Encode the entire PDF URL, especially when it includes its own query string, an ampersand, spaces, or signed parameters:
const pdfUrl = '/documents/brochure.pdf?edition=summer&lang=en';
const viewerUrl = '/pdfjs/web/viewer.html?file=' +
encodeURIComponent(pdfUrl);
For example, a remote PDF URL can be passed the same way:
const pdfUrl = 'https://cdn.example.com/brochure.pdf';
const viewerUrl = '/pdfjs/web/viewer.html?file=' +
encodeURIComponent(pdfUrl);
Do not manually encode only spaces or concatenate an unencoded URL: its & characters can be interpreted as parameters of viewer.html rather than as part of the PDF address.
Rank #3
- Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
- Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
- Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
- In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
- Ultra-thin bezels: Maximize your viewing experience with thin bezels.
Generate the viewer URL from a normal link
For a list of documents, preserve each PDF URL as the real link destination and derive the viewer URL for Fancybox:
<a class="js-pdf" href="/documents/brochure.pdf">View brochure</a>
<script>
$('.js-pdf').each(function () {
const pdfUrl = this.getAttribute('href');
this.setAttribute(
'data-src',
'/pdfjs/web/viewer.html?file=' + encodeURIComponent(pdfUrl)
);
this.setAttribute('data-type', 'iframe');
this.setAttribute('data-fancybox', '');
});
$('.js-pdf').fancybox({
iframe: { preload: false },
toolbar: false,
smallBtn: true
});
</script>
If documents are selected dynamically, open the same viewer URL programmatically:
$('[data-open-pdf]').on('click', function (event) {
event.preventDefault();
const pdfUrl = this.getAttribute('data-open-pdf');
const viewerUrl = '/pdfjs/web/viewer.html?file=' +
encodeURIComponent(pdfUrl);
$.fancybox.open({
src: viewerUrl,
type: 'iframe',
opts: {
iframe: { preload: false },
toolbar: false,
smallBtn: true
}
});
});
Set usable modal dimensions
PDF.js is a full viewer interface, so give the iframe enough room rather than relying on Fancybox to infer the document’s dimensions:
Rank #4
- CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
- SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
- MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
- KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
- INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
.fancybox-slide--iframe .fancybox-content {
width: 90vw;
height: 90vh;
max-width: none;
max-height: none;
margin: 0;
}
@media (max-width: 600px) {
.fancybox-slide--iframe .fancybox-content {
width: 100vw;
height: 100vh;
}
}
The .fancybox-slide--iframe .fancybox-content selector follows Fancybox 3’s documented iframe-sizing approach. Fancybox 3 sizing examples A 90% viewport modal leaves margins; a full-screen layout gives a phone more reading space. On small screens, test that the PDF.js toolbar remains practical and the modal close control is reachable. If the modal feels cramped or the document is central to the task, a dedicated viewer page is often a better fit.
Same-origin PDFs are simplest; remote PDFs need permission
A local viewer and local PDF commonly avoid cross-origin complications:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11https://www.example.com/pdfjs/web/viewer.html
https://www.example.com/documents/brochure.pdf
If the PDF is on a different origin, the browser must be allowed to fetch it from that origin. A public URL is not automatically fetchable by PDF.js. Check the PDF host’s CORS response, including Access-Control-Allow-Origin, any required request headers, redirects, authentication or cookies, and CDN rules. Confirm the response is actually a PDF (normally Content-Type: application/pdf), rather than an HTML login or error page.
Best Value
- 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
- 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
- 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Also check production security and routing: an HTTPS page cannot safely load an HTTP document; a Content Security Policy may block the viewer, worker, or PDF; frame-ancestors or X-Frame-Options can block framing; and proxy rewrites or incorrect base paths can break viewer assets. If a remote host cannot be configured for browser access, an application-side proxy is an option only where legally and operationally appropriate.
Troubleshoot by symptom
- No PDF.js toolbar: Inspect the iframe URL. It should load
/pdfjs/web/viewer.html?file=..., not the raw.pdf. - Viewer appears, but the page is blank: Verify the encoded
filevalue, the PDF’s browser-accessible response and content type, CORS if cross-origin, and any expiring signed URL or required credentials. Confirm the PDF.js viewer and worker assets are deployed together. - Works locally but not in production: Compare origins, subdomains, paths, redirects, HTTPS, CSP and iframe response headers. A local setup may hide a production CORS or deployment-path problem.
- Viewer works directly but fails in the modal: Check iframe width and height, the
preloadsetting, CSS overrides, duplicate jQuery or Fancybox scripts, and browser console errors. Initialize Fancybox before the trigger is used.
When a modal is the wrong choice
Use this integration when an existing Fancybox 3 site needs an in-page preview with PDF.js controls and can serve the viewer and document appropriately. A regular PDF link is simpler and lets the browser choose its native viewer. A PDF.js iframe on a dedicated page provides more space and is generally better when deep links, browser history, sharing, or extended reading matter. A modal also adds focus-management requirements: test keyboard navigation, Escape-to-close, focus return to the trigger, and whether the background page remains confusingly interactive.
For a new project, evaluate the modal library and document-viewing approach independently; Fancybox 3’s jQuery API is specific to this legacy integration, not a drop-in recommendation for a modern application. Check the PDF.js project’s current build and deployment guidance before choosing assets. The SitePoint discussion that prompted this pattern dates to February 2019, so its linked demo assets should not be assumed to be appropriate for production today. SitePoint discussion
Recommended Free Tools
Quick Recap
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.

