Using Mozilla’s JavaScript PDF Viewer in XPages

I’m doing a lot of mobile stuff these days, but XPages is another big part of my work and this will not change in the foreseeable future. One project I’m working on is a tool to put iNotes mails into an archive system.

While doing that, the user should be able to view attachments a mail might have – including PDFs. View means viewing in the browser, not downloading the file to the computer. But exactly this happens when you open a typical Domino URL like /db.nsf/0/<UNID>/$FILE/filename.pdf.

You can display images inline using the embed tag. That’s very simple. But that does not work for PDFs. So what now?

Lucklily, there are various JavaScript based PDF viewers out there. I tried Mozilla’s PDF.js and found it very easy to integrate:

  • Download the stable version from http://mozilla.github.io/pdf.js/getting_started/#download
  • Extract the archive to some folder. In Designer, open the Navigator view, navigate to the WebContent folder, rightlick and select ‘import’, then import the folders ‘web’ and ‘build’ into the NSF.
  • Now you can call the PDF viewer with an URL like this: http://host/db.nsf/web/viewer.html?Open&file=/db.nsf/0/<UNID>/$FILE/file.pdf

It’s impressive what’s possible with JavaScript, isn’t it?


4 thoughts on “Using Mozilla’s JavaScript PDF Viewer in XPages

  1. Julian, I looked at using pdf.js but found some inconsistency with how it rendered the pdf. I ended up wrapping the pdf in an iframe. It worked well as it used the native pdf viewer in the browser, working well in iOS as well. Are you running into any problems with PDF’s not rendering properly? I love the idea of rendering the pdf’s serverside, rather than serving the pdf’s up fat.

    • I just tried some simple PDFs, and that worked fine. The customer mostly wants to view scanned paper, so I assume that would be no problem.

  2. It is very interesting to read that there is XPages work to do: In the Rhein-Main-Area there are no Projects during the last two years, and this year only 5% of my projects where XPages relevant.

    • I cannot complain at all. I had three customers with constant demand for XPages work and just won one other customer. Beside that I have some other customers with small to medium XPages projects here and there.
      Nevertheless, it’s always a good idea to have competence in other areas, too 🙂