Hacker News new | comments | show | ask | jobs | submit login
Google's Javascript PDF Viewer is Embeddable (googlesystem.blogspot.com)
115 points by blasdel 2604 days ago | hide | past | web | 54 comments | favorite

For HN as an alternative to scribd's vaccuum maybe?

scrolling/zooming even works! die flash, just die.

Until you said that, I didn't even realize it wasn't flash. This rocks!

But it isn't text....

Text copy wont work.

I really dont see anything new here. This is exactly the same stuff they have at Google books. Except now its in an iframe .

Flash implementations are obviously superior as of now.Also, try building a decent browser game in javascript and html5.

Actually games that don't involve too much motion tweening (think sudoku, tic tac toe etc.) can be done pretty well with js and html5.

any live examples?

This is old but this version of arakanoid was always pretty impressive.


Note it does cheat and use flash for SFX

Nope, it was just a thought. You're just going to be changing the innerhtml of DOM elements. Shouldn't be tough.

John Resig's Deep Leap: http://deepleap.org/

Text copy worked for me. (Firefox 3.5, Ubuntu Jaunty)

It also works as its own page: http://docs.google.com/gview?url=

Does anyone know if firefox extensions can register as handlers for MIME types, or if they're restricted to diddling with chrome / pre-existing pages? It'd be really easy to write a WebKit plugin to do it, but not very useful since Safari ships with a flawless PDFKit-based viewer.

I want to get this working in Firefox, but NPAPI plugins are really gross. It looks doable that way, as it appears that a naked nsplugin still gets a DOM and everything, so I could just immediately set window.location.href and be done with it.

It sounds like you're looking for window.navigator.registerContentHandler:

...except a website can only register themselves as a content-handler. You could probably hack up a bookmarklet to do it, if you can't find an XSS vector, but I can't seem to make it work myself.

So... close...

It'd be easy to make a greasemonkey-style extension that calls this on *, but it wouldn't work for links to other domains (which I'd bet are the majority of PDF links)

That would already be very useful though, for things like online papers and datasheets, which as a rule sit on the same server as the page you're looking at.

It's becoming more common to use a separate domain for static content like this to be cached more effectively (and to have no cookies etc sent), so it may not always be the same server as the page you're looking at.

It's good to know that there are alternative ways to embed PDFs, but I'm a little confused by the reaction in the comments. Is this a big improvement over simply using the object tag?


Yes, for a wide variety of reasons:

  * Before version 8, Adobe's plugin was an epic piece of shit on all platforms
     - old versions are on hundreds of millions of computers!
     - it's still really crashy on Linux (especially in nspluginwrapper)
     - The only OS X browser they support is Safari, in which it is unnecessary
  * Google re-hosts the file for you
  * It is ridiculously snappy with no main-thread-blocking initialization
  * It will never crash your browser
  * Your users don't have an ingrained hatred towards it
      - Rebranding the free Acrobat as "Adobe Reader" was the stupidest thing
        they've ever done (ever hear a user say 'my Adobe is broken'?)

I can't tell if you're being facetious in your last line, but I used to work at a place requiring, in their own words, "Adobe must be installed on every computer" long before they changed the Acrobat name.

It's images! Is that really better?

It's not text layed (laid?) out in a cool way with HTML.

It's a png image of each page of the pdf. It's quick sure, but images? Not text? It just seems wrong - why even make pdf's, if all you want is an image of the text?

Generating an image from the PDF server-side is the only way to faithfully perserve the layout of the PDF.

For some PDFs, Google will give you the option to view it as HTML (it seems to just be the PDFs returned in search results?). It's usable for mostly-text documents, but that's about it.

I hope somebody makes a Firefox addon which lets me right-click on a PDF link and select "Preview" using the Google previewer.

There's this, but it sucks:


You click a link and it first does some communicatin with Google Docs to get some kind of security token, so it takes 2-3 seconds for the new tab to come up.


A kickass version, just uploaded it to the Firefox Addons site:


I think that addon is worse than you describe: doesn't it add the files to your logged-in Google Docs account, and do so by uploading said files from localhost?

You're right, I just checked my Google Docs and it added the files. The hacked version just opens the URL and passes in the PDF url as a HTTP param.

You mean the second link in your granparent post, right? Thanks for that -- works for me. I was looking for something like this just the other day.

But I don't want to right-click -- adding bloat to the chrome is entirely the wrong way to go about doing this, but unfortunately Mozilla has a bug up their ass and won't let you do it right as an extension.

The right way is to register application/pdf in the browser -- which you can only really do with a native-compiled NPAPI plugin. It looks like it is possible to package them inside a extension xpi, but I'm not sure if addons.mozilla.org will distribute such things.

This is very cool. My only gripe is that if they are going to fake their own selection, then they should override command-a (select all). I tried this, and now I have google's selection AND the entire page selection, which I can't get rid of.

I hope that it will be extended to TeX, PostScript and ODF as well.

The viewers for the first two formats are lagging in the UI department, it would be really nice to be able to access them online.

I presume one can't use this viewer in your own project (e.g. as a file viewer in a web app).

Does anybody know of similar project but that can be used in your own web app?

Quick Googling suggests that http://vuzit.com/ would work.

You might also be able to hack Thindoc in such a way that it worked for your purpose.

Don't know why you're downmodded.

I use http://www.ajaxdocumentviewer.com/ on my own personal site. It works the same way as Google (but has ads), and handles .doc files.

I'd much rather use the Google app if it could handle .docs :(

If you serve PDFs with public URLs that Google can GET, you can use this in your web app.

I think he is talking about it being risky to assume that the undocumented cross-site embedding is a feature Google is committed to supporting in the coming years and not, say, a wee unintended data leak that any engineer in their megacorp could plug at any time, including smack-dab in the middle of your public launch.

But it didn't do this before -- you used to have to explicitly upload the files to a Google Docs account.

Someone explicitly added this feature, and I imagine that it will replace the lame "View as HTML" links on SERPs very soon. This ain't going away.

It won't replace view as HTML because it's images of the text, not the text itself.

It does contain the selectable text where available.

The real problem is that it's an empty-window UI -- it does nothing without Javascript on.

You can always replace it with an <object> tag.

I wish their Chat Window on Google Spreadsheet were embeddable , too.

Scribd must love this

Do you think the same thing exists for Word documents?

Can anyone confirm if this works in Internet Explorer?

It does. Even current versions of IE can show PNGs in iframes, believe it or not ;-)

Very smooth, but why does it lack a search box?

The full page version has a (pretty good) search function. I'm not sure why they don't have it the embedded one. Even if you just got taken to the results in the full version.

ACtually the full page version highlights the results but doesn't navigate to them. Also it seems to be substring search, not an indexed one.

no search, no print, no save in the viewer. you must always open the new window...

Here is a bookmarklet I just wrote to look at all the links on a page and open any ending in ".pdf" in google's viewer. (if you have firefox set to open tabs for windows, it will open them in new tabs) Feel free to share and improve.

- - - (select entire text and make into a link) - - -


- - -

I made this into a greasemonkey userscript. It searches for PDF links on a page and sets them to open in Google's pdf viewer.

Userscript at: http://userscripts.org/scripts/show/57453

Tested on Minefield latest nightly, winxp, greasemonkey.

Thanks! It needs to not work on http://docs.google.com so that you can click the "Download" link if you need to...otherwise you are stuck in a loop. Also, I noticed that the search on the full-screen page isn't always available (ie http://bit.ly/4tf1xt)

About the search not being available, I think it's something to do with google's implementation, not the script. The other, I'll fix ASAP.

Edit: Fixed version available now.

This one transforms the links rather than opening them automatically. For pages with a lot of pdf links.


Fixed a missing quote and added void(0) at the end:


Without the lambda, you run the risk of overwriting dl in the global scope, which could cause another script to misbehave.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact