Home  »  Javascript  »  PDF.js

by 1 comment

PDF.js Iconpdf.js is an HTML5 technology experiment that explores building a faithful and efficient Portable Document Format (PDF) renderer without native code assistance.

pdf.js is community-driven and supported by Mozilla Labs. Our goal is to create a general-purpose, web standards-based platform for parsing and rendering PDFs, and eventually release a PDF reader extension powered by pdf.js. Integration with Firefox is a possibility if the experiment proves successful.

Viewer Constants

var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
var DEFAULT_SCALE = 'auto';
var CACHE_SIZE = 20;
var CSS_UNITS = 96.0 / 72.0;
var MIN_SCALE = 0.25;
var MAX_SCALE = 4.0;

Viewer options

Options for pdf.js's viewer that can be given at the URL level. This page is current as of 2013 April 21.

Multiple values of either type can be combined by separating with an ampersand (&) including after the hash (Example: #page=2&textLayer=off).

Options after the ?

var params = PDFView.parseQueryString(;
var file = params.file || DEFAULT_URL;
  • file=file.pdf: pdf filename to use

Options after the #

// Special debugging flags in the hash section of the URL.
var hash = document.location.hash.substring(1);
var hashParams = PDFView.parseQueryString(hash);
  • page=1: page number
  • zoom=100: zoom level
  • nameddest=here: go to a named destionation
  • pagemode=[thumbs|bookmarks|outline|none]:
  • locale=en-US: set a localization
  • textLayer=[off|visible|shadow|hover] - Disables or reveals the text layer that is used for text selection.
  • disableRange=true: set to true to disable chunked/206 partial content viewing, load entire pdf from start
  • disableAutoFetch=true: If there are no pending requests, automatically fetch the next prevent unfetched chunk of the PDF
  • disableWorker=true - Makes it easier to use debugging tools like firebug. Support, create a new web worker and test if it/the browser fullfills all requirements to run parts of pdf.js in a web worker
  • disableFontFace=true: use custom fonts
  • disableHistory=true: manipulation of the history
  • pdfBug=all - Enables all the debugging tools. You can optionally enable specific tools by specifying them by their id e.g. pdfBug=FontInspector or pdfBug=Stepper,FontInspector


Debugging PDF.js

URL Parameters

pdf.js has several special url parameters to alter how pdf.js works and enable debugging tools. All of these parameters go into the hash section of the url (after the # symbol) and follow a query string syntax (e.g. #param1=value1&param2=value2). Note: since all of these parameters are in the hash section you have to refresh the page after adding them.

if ('pdfBug' in hashParams) {
  PDFJS.pdfBug = true;
  var pdfBug = hashParams['pdfBug'];
  var enabled = pdfBug.split(',');
  • pdfBug=all - Enables all the debugging tools. You can optionally enable specific tools by specifying them by their id e.g. pdfBug=FontInspector or pdfBug=Stepper,FontInspector. More about PDFBug below.
  • disableWorker=true - Disables the worker which makes it easier to use debugging tools like firebug where workers aren't supported yet.
  • textLayer=[off|visible|shadow|hover] - Disables or reveals the text layer that is used for text selection.

PDFBug Tools

To enable see above.

Font Inspector

id: FontInspector

The font inspector allows you to view what fonts are used within page. It also allows you to download the font using Save Link As.. and naming it with a .otf extension. See the section below on debugging fonts.


id: Stepper

The stepper tool makes it so you can step through the drawing commands one at a time and hopefully find where a possible issue is coming from. It is also useful for learning how a PDF is structured and the order of its operations. To walk through the drawing commands first add a break point, refresh the page and then use the keys s to step one command at a time or c to continue until the next breakpoint(line that is checked).

github pdf.js Wiki Docs

Full list.

More Info


September 16th, 2013

Comments Welcome

  • Bhavesh shah

    please sir help me. how to generate jasper report in pdf format using pdf js.

Popular Articles
My Online Tools

Related Articles
Newest Posts

  • @askapache · Jul 21
    Magic spells for sending thoughts across time? Books
  • @askapache · Jul 20
    TV is just a relic of the previous generation. We just don't know it yet.
  • @askapache · Jul 20
    I will never go back on my ideals, no matter the cost. I'll never let the economic vultures steal my dreams. I'd rather give up the ghost
  • @askapache · Jul 18
    I don't want a better seat, I want control of the engine
  • @askapache · Jul 14
    No matter how good u r, there will always be someone 2x, 5x, 100x better. This is true for me and everyone. No direction but forward.
  • @askapache · Jul 12
    Heads up, I'll DDoS the f out of askapache next week, to see how resilient it really is :) - will try to overflow disk, net, and ip stack
  • RUN GCC! This is a typical shirt I wear, from the  shop. A clerk at the LQ recognized it! 
  • Merlin the Magician 
  • ROGUE CODE - Latest novel from @markrussinovich 
  • RTFM - surprisingly very helpful and way more comprehensive than it looks! @redteamfieldman #pwnAllTheThings 
  • Dear Hacker - Letters to the Editor of 2600, from Emmanuel Goldstein 
  • The Mythical Man-Month - Essays on Software Engineering, by Frederick P. Brooks, Jr. 
  • "where wizards stay up late" - The Origins of the Internet. Favorite book detailing the birth of the net and IMPs 
  • ZERO DAY - read before Trojan horse 
  • Trojan Horse, a novel! 
  • The Hacker Playbook - very nice high level overview of attacks 
  • Clean Code - A Handbook of Agile Software Craftsmanship 
  • Secrets of the JavaScript Ninja - By my absolute favorite JS hacker John Resig! 
  • Hacking Exposed 7: Network Security Secrets & SolutionsMy all time favorite, basic but thorough and accurate. 
  • Empty words will be no surrogate for cold resolve. Pain is nothing. 

Hacking and Hackers

The use of "hacker" to mean "security breaker" is a confusion on the part of the mass media. We hackers refuse to recognize that meaning, and continue using the word to mean someone who loves to program, someone who enjoys playful cleverness, or the combination of the two. See my article, On Hacking.
-- Richard M. Stallman


It's very simple - you read the protocol and write the code. -Bill Joy

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. NCSA HTTPd.
UNIX ® is a registered Trademark of The Open Group. POSIX ® is a registered Trademark of The IEEE.

| Google+ | askapache

Site Map | Contact Webmaster | License and Disclaimer | Terms of Service

↑ TOPMain