question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pdf.js relies on urls to contain the 'pdf' extension

See original GitHub issue

When the server doesn’t provide the Content-Disposition header, pdf.js relies on urls to contain the ‘pdf’ extension. But URLs are locators, not names. Steps to reproduce:

mv web/compressed.tracemonkey-pldi-09.pdf web/compressed.tracemonkey-pldi-09
sed -i 's/compressed.tracemonkey-pldi-09.pdf/compressed.tracemonkey-pldi-09/g' web/viewer.js
firefox web/viewer.html

Now click on download. You will be offered a ‘document.pdf’ file. The name should be something more meaningful. The bug also happens when I leave out the pdf extension on my apache web server.

Proposed solution: Use the title of the pdf. (as this viewer.js code). The title is also used by firefox for the File -> “save page as” functionality when displaying a HTML page like http://en.wikipedia.org/wiki/Internet_media_type .

Not every html web page ends in .html. Instead by the extension, a document’s type is specified by its MIME-type. However, most pdf files have the pdf extension, and most pdfs online also have a good-to-store name in the url. I don’t know whether the new retrieval method should overwrite the url retrieval, or be a fallback to it.

See also #3455.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
timvandermeijcommented, Aug 23, 2016

Sorry, I should have been more clear. I meant that patches are welcome for improving the function that determines the file name from the URL. I think we can do better there instead of only relying on the file extension. I agree that we should not add more hash parameters.

1reaction
Snuffleupaguscommented, Aug 23, 2016

Patches for this are welcome, so I’m labeling this as a good beginner bug as it should not be too hard to implement.

@timvandermeij Please remember that in PR #4956 we purposely moved away from letting various hash parameters affect the viewer (unless debugging is enabled, see https://github.com/mozilla/pdf.js/wiki/Debugging-pdf.js). Hence I do not think that we should make it possible to specify the title using a hash parameter!

Especially considering that it would be non-standard (in the context of http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf), and compared to the Content-Disposition approach in PR #7554, it really doesn’t add much value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frequently Asked Questions · mozilla/pdf.js Wiki - GitHub
You can use raw binary data to open a PDF document: use Uint8Array instead of URL in the PDFViewerApplication.open call. If you have...
Read more >
Show a pdf document on a webpage but with substituted links
First I was trying to extend the PDFViewer class from the web/pdf_viewer.js in the pdfjs-dist npm package, but I didn't manage to find...
Read more >
Edge is saying page with PDF is a suspicious site!
I just replaced another PDF viewer with yours. And it works fine, but when viewed on Edge it says site is suspicious. Not...
Read more >
Examples
PDF.js heavily relies on the use of Promises. ... var url = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf'; ...
Read more >
Custom PDF Rendering in JavaScript with Mozilla's PDF.Js
Take control of rendering PDF documents in the browser. Imran Latif introduces PDF.js as a flexible solution for custom PDF rendering with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found