pdf.js: [Bug]: Adding a `` tag to a page containing a pdfjs viewer breaks transparancy filters in Firefox.

Attach (recommended) or Link to PDF file

https://github.com/mozilla/pdf.js/files/11229069/test.pdf

Web browser and its version

Firefox 127.0.2

Operating system and its version

Mac and Windows

PDF.js version

4.5 (master)

Is the bug present in the latest PDF.js version?

Yes

Is a browser extension

No

Steps to reproduce the problem

  1. Running local copy of pdfjs using npx gulp server
  2. Add <base href="." /> to viewer.html
  3. Open test.pdf

What is the expected behavior?

The PDF should render the same regardless of <base href>

image

What went wrong?

When rendering a pdf in Firefox when a <base href> is defined the drop shadow is not rendered correctly.

image

Link to a viewer

No response

Additional context

This issue was discovered and discussed here: https://github.com/stephanrauh/ngx-extended-pdf-viewer/issues/2363

We tested accross multiple browsers, OSs, sites, and PDFs. The issue was eventually narrowed down to pdfjs v4.3-v4.5 in Firefox when the site defines a <base href>. Many SPAs require a base href to be defined. This issue was not seen in other browsers nor in pdfjs v.4.2. It was seen in Firefox regardless of OS.

Additional note: Relatively certain this issue is SVG IRI references in display_utils.js.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

@calixteman I was thinking !!this.#document.querySelector('head base')?.attributes.href.value or something like that.

What about docBaseUrl defined in api.js (see below).

Please see: https://github.com/mozilla/pdf.js/blob/1bdd6920ff0b443ab7893ee103d8185bcf2bb7f2/src/display/api.js#L139-L141

Can we pass that into the DOMFilterFactory constuctor?

No, that’s not appropriate since (as documented) it has a completely different purpose.

Is src.docBaseUrl the same as what you’ve defined in the createUrl method?

No, that parameter is user defined and can be any valid URL.

The smallest patch I could imagine, assuming that we actually want to attempt to fix this, would be something along these lines (with the functionality limited to GENERIC builds): https://github.com/mozilla/pdf.js/compare/master...Snuffleupagus:pdf.js:DOMFilterFactory-baseUrl

Another idea I had was if the SVG rendering could be done in another document (using something like createHTMLDocument )… but I don’t really have a grasp of how that works.

That sounds essentially like the following getDocument parameter: https://github.com/mozilla/pdf.js/blob/1bdd6920ff0b443ab7893ee103d8185bcf2bb7f2/src/display/api.js#L194-L196