I am spending hours trying to figure out how to make this module work.
Everytime I click on the pdf document it open a windows window for download. How can i see the viewer?
please step by step documentation.

Comments

Zarevac’s picture

Did you follow the instructions that are on the main page of this mod?

shenzhuxi’s picture

Status: Active » Fixed

I copied the instruction from the module page to README.txt FTLOG.

:D

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lpalgarvio’s picture

Version: 7.x-1.x-dev » 7.x-1.1
Category: support » task
Priority: Normal » Critical
Status: Closed (fixed) » Active

does not suffice

i've figured out to compile pdf.js in windows, which is a long and steep curve for newbies (not so bad in linux).
describing shortly...

REQUISITES FOR THE MODULE:
- node.js: binary or source
- pdf.js // download: source

REQUISITES FOR node.js (binary):
- Python interpreter: install package Python v2.7 in *nix, setup Python v2.7 for windows
- make: install package make in *nix, make is provided with node.js binary for windows

REQUISITES FOR node.js (source):
- Python interpreter: install package Python v2.7 in *nix, setup Python v2.7 for windows
- C++ compiler: install package g++ in *nix, setup MinGW (includes G++) OR CygWin (add G++) for windows
- make: install package make in *nix, make is provided with MinGw, add make to CygWin for windows

REQUISITES FOR pdf.js (source):
- Python interpreter: install package Python v2.7 in *nix, setup Python v2.7 for windows

INSTRUCTIONS (binary node.js, windows):
- download and install Python 2.7 (msi/setup)
- add Python directory to your %PATH%
- copy Python.exe to Python2.7.exe (node.js will look for this non-existing file)
- download and install node.js (binary)
- download and extract pdf.js archive
- navigate to pdf.js directory on the command line and execute: node make generic
- upload the contents of pdf.js-master/build to /sites/all/libraries/pdf.js
- enable module
- add File field (file or media widget)
- file widget: configure field display to PDF in full/default view
OR
- media widget: configure field display to Rendered file: default in full/default views, and add PDF display to the File type Application -> default view

then sadly, watch and see it not function for no file is given as argument to pdf.js...

lpalgarvio’s picture

INSTRUCTIONS (source/binary node.js, debian/apt *nix):
- open terminal and execute:
apt-get install python
(might require 2.7 instead of 2.5 or 2.6)
- follow node.js make/install instructions here
- execute in the terminal:

wget https://github.com/mozilla/pdf.js/archive/master.tar.gz
tar  -zxvf master.tar.gz
cd pdf.js-master
node make generic

OR

git clone git://github.com/mozilla/pdf.js.git pdfjs
cd pdfjs
node make generic

drupal steps are identical

lpalgarvio’s picture

or download pdf.js from here
and place it on /sites/all/libraries/pdf.js

lpalgarvio’s picture

installing node.js and npm on debian 6.0 (squeeze):
- add testing and unstable repos to debian as described here for example (add priorities), as node.js and npm aren't included in stable nor updates
- add node.js packages:
apt-get install libv8-dev/testing libssl-dev/testing libev-dev/testing libc-ares-dev/testing libc-ares2/testing nodejs/unstable npm/unstable

bazzly’s picture

So does this thing even work anymore?

shenzhuxi’s picture

README http://drupalcode.org/project/pdf.git/blob/refs/heads/7.x-1.x:/README.txt

If you use "PDF default" display rather than "PDF first page", you don't need to compile pdf.js.

bazzly’s picture

Yes I have read that and spent hours on it...No matter what I do it does not work, even if I use the pre-compiled version.
With the pre-compiled the pdf does not show up, all I get is a box with arrows for next page and re size the doc. It looks like it wants to show the pdf, but can only show it as a blank pdf. (If that makes any sense.)

bazzly’s picture

Anything??

vodde83’s picture

What I did, to make it work in Windows / Drupal 6 :

- Installed PDF module
- Downloaded ZIP from from https://github.com/mozilla/pdf.js , en put everything in /sites/all/libraries/pdf.js folder
- Downloaded Windows installer from http://nodejs.org/download/
- Added the install folder of nodejs, to my PATH variable, so I can call 'node' command from command line
- Through command line, browsed to /sites/all/libraries/pdf.js
- Typed 'node make generic'

I wanted to make the Full viewer work, so I started debugging that

The Full viewer is called through file/pdf_viewer/%node, and the menu callback for that URL, is pdf_js_viewer function.
That function however, gets the file like this :

$file = $node->field_filefield[0];

My field wasn't called 'field_filefield' however, so I replaced that with my field name.

The pdf_js_viewer function, in turn calls the theme function 'pdf_viewer', which resolves into the template pdf-viewer.tpl.php, located in the PDF module folder.
In that template file, theres a JS block :

      kDefaultURL = '<?php print $file_url; ?>';//overwriting kDefaultURL value and inserting our desired file URL...
      var file_node_id = '<?php print $nid; ?>';//variable used in notes js
      var lang = '<?php print $language->language; ?>';

However, I had to replace 'kDefaultURL = .. ' in that JS block, to 'DEFAULT_URL = .. '.

After that, when I browsed to file/pdf_viewer/[node_id] , I succesfully saw the PDF.

bazzly’s picture

Thanks for the info. I'm using linux so I'm trying to apply what you wrote.

Should 'node make generic' have any output? When I do it, there is not out out, no hang or anything... its just like hitting enter.

And if I use the pre-built pdf.js all I get is a frame for a PDF. Just a white page, it has all the buttons for the PDf, but no content/pdf.

shenzhuxi’s picture

Status: Active » Closed (fixed)

For people who ask help for Drupal 6, please create new issues with the right version.
By the way, NadimBak is the author of the Drupal 6 version.

bazzly’s picture

I'm using D7... So what would cause a empty PDF?

bazzly’s picture

Well Got it working.

My steps

I'm using lubuntu with D7
I downloaded the module and placed it in the usual place. drupal/sites/all/modules

sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

npm did not install and I didnt' have the Amateur Packet Radio installed so I didnt need to do the symlink or uninstall it.

git clone git://github.com/mozilla/pdf.js.git pdfjs
cd pdfjs
node make generic

Where I was running into the problem was when I did git, I followed the directions for the directory pdfjs. So git made the directory pdfjs and not pdf.js, so once I renamed the directory it worked.

So for those who tried to help thanks!

bailey86’s picture

My steps for getting this module to work on a Debian Squeeze - for Drupal 7. It took a while to figure out and some wrong turns were made so there might be an error in these steps.

OK - So what's going on? I'm not sure - but here's my rough take on it.

The server needs to have something called node.js installed. What is this? It is a Javascript engine. I'm not sure how it is used by this module.

This is not available as a package for Debian Squeeze. So, it has to be installed.

It can be installed from source directly on to the server with the old ./configure, make, make install stuff - but I would suggest a slightly different method. Compile it to a Debian package and then install the package. That way - I figure - it will be easier to remove if there are any issues.

Install node.js

First we need some tools.

# apt-get install python-software-properties python g++ make checkinstall

Now we will download node.js and build the deb to install. It doesn't matter where we download it to - it just needs somewhere to compile.

$ mkdir ~/src && cd $_
$ wget -N http://nodejs.org/dist/node-latest.tar.gz
$ tar xzvf node-latest.tar.gz && cd node-v*
$ ./configure

So, we've downloaded the latest node.js, unzipped it and run configure in the unzipped directory.

The following command needs to be run as root. Not sure if this is completely correct - but it worked for me.

# cd directory-to-node-just-downloaded
# checkinstall

When the script asks questions answer as best you can - I went with the defaults.

This looks like it then compiles the required deb file and installs it. You can check that the package is installed with:

# dpkg -l node*

Install the module

Download and enable the Drupal module pdf.

Install pdf.js

OK - So now we pull down the pdf.js library. The module then uses this library - and I think this library needs to use the node.js engine.

$ mkdir sites/all/libraries
$ git clone https://github.com/mozilla/pdf.js

This then seems to work. It looks like we should run

$ node make generic

but currently the module is working - so I'm leaving it where it is for now.

Use the module

OK. Go to a content type, add a field of type file.

Make sure you add the file extension 'pdf' to the allowed file types. After you've added the field click on the 'Manage Display' and select the format 'PDF default'.

Add a node and upload a PDF - this should then show up in a box when the node is viewed.

One problem - we apparently can't get the PDF to view correctly in IE9 on Windows 7. Apparently, I might have to actually compile the PDF.js - and there are notes referring to compatibility.js - but I don't know how to install it yet.

bailey86’s picture

OK - so it's looking good.

Works on Chrome, Firefox on Ubuntu and looks OK on an S4 and a Nexus 10 and an iPad.

But - I've heard reported that it only loads the second page on IE9 on WIndows 7.

So, I've cd'd into sites/all/libraries/pdf.js and run

$ node make generic

but IE9 is still not happy.

On the site for PDF.js - https://github.com/mozilla/pdf.js/ it mentions:

Also, if you would like to support more browsers than firefox you'll also need to include compatibility.js from build/generic/web/

I'm not sure how this works - and whether or not the compatibility.js has been included when I ran 'node make generic'.

bailey86’s picture

OK - an update.

IE9 on Windows 7 is OK. It was just one particular PDF which didn't render the first page - maybe because it was a page with a large graphic in it.

I've tested with a 39 page PDF which was a sort of Powerpoint looking brochire type thing and it has all rendered fine.

bailey86’s picture

As a further update.

I've just moved the site to another server - so moved from a squeeze server to a wheezy one.

So, I've moved the database and all the files - including the libraries directory. And the PDF field is working even though I've not installed node on the new server.

So, I'm going to guess that the only reason to compile and install the 'node' package is to be able to run 'node make generic' to compile the the library which has been downloaded.

thanasis57’s picture

Issue summary: View changes

Lots of thanks to bailey86 for taking the trouble to note the installation steps.

Following up on observation #20, I installed node.js on my laptop and compiled pdf.js locally. Then I gziped the pdf.js directory, uploaded in my server at /sites/all/libraries and unzipped there.

So I avoided installing extra packages on my server, which could also (though doubtful) entail security risks. It is also a good solution for people with shared hosting (i.e. without ssh access).

Since documentation of this module is an issue, here are a couple of extra tips:
-To remove the "Open", "Print" and "Download" buttons from the secondary menu (in the primary they are hidden by default), edit the pdf.js/web/viewer.html file, lines 151-161. There, you have to add a "hidden" class.
ATTENTION: Deleting or commenting out those buttons leads to pdf's not being rendered at all.
-Version 7.x-1.5 has an issue with the width of the window (it is too narrow and I could not correct it with css). I uninstalled and downloaded 7.x-1.4 which works fine (using pdf.js version 1.0.68).

Surf New Media’s picture

I am lost in getting this to be generic. Is this something I could pay someone to do or is it server specific?

thanasis57’s picture

@Surf New Media (#22)
What exactly are you referring to? Which post/feature troubles you?

Surf New Media’s picture

I would like to compile the pdf.js so that I can just use the "show first page" option. Right now I am using default, but cannot for the life of me figure out how to compile anything. I know it is my own lack of knowledge in it, and didn't know if I could / should go into the paid services items on the site to see if it can be done by someone or if it was server specific that I would have to try to figure out.

Surf New Media’s picture

This might help someone else .... It helped me with #22 and #24: http://mozilla.github.io/pdf.js/

thanasis57’s picture

The above instructions are pretty clear. They are also very easy to follow, assuming you have an elementary knowledge of some *nix OS (Linux/OSX/BSD) and the command line (e.g. I use Linux and have never tried anything like this on Windows).

Put briefly, your question is not Drupal-related. Yes, you could have someone do it for you, but it's a really simple job.

AlejandroSalinas9294’s picture

Hello,

I am trying to get this to work on Drupal 6.31 with no success so far. the name of my file field is field_filefield and I also renamed the kDefaultURL to DEFAULT_URL. I still have no luck, the iframe displays a copy of my website's page not found page. It looks like the viewer is never actually loading. Any ideas?