shivaprsd / doqment

Mozilla's HTML5 PDF Viewer with Reader-mode add-on. 📖
https://shivaprsd.github.io/doqment/src/pdfjs/web/viewer.html
MIT License
49 stars 1 forks source link

Two questions #15

Closed cxw-droid closed 3 months ago

cxw-droid commented 7 months ago

hello, thank you for your work.

  1. After installing the plugin in Firefox, when I try to open a pdf file with 'open with Firefox`, it does not open the pdf file directly. I need drag the file to the browser. Is there any way to directly open a pdf file?
  2. Do you know how to set set about:config in Firefox to get the same effect? When I set pdfjs.forcePageColors to true and pdfjs.pageColorsBackground to a hex value, it changes both the background and the image color in the pdf. In fact, I want to change the background color only.

Thanks.

shivaprsd commented 7 months ago

@cxw-droid Thanks for stopping by! To answer your questions:

  1. Do you mean when you right click a PDF file in your OS file manager and choose Open with Firefox? Unfortunately, no. I am sorry, but this is a restriction imposed by Firefox on us. As much as I also want this to work, Firefox does not let extensions access file:/// URLs (which is what it gets when you do the above action). Here is the relevant function (note how it says 'Firefox will always return false'). It works when you drag and drop because then the extension gets the file itself in that case.
  2. Again, sorry, I cannot help you here. I am aware of those options in pdfjs, but I don't know how they work and why it would modify image colours. You would be better off asking this in the PDF.js repo, they can provide the correct method (if any). Although I am also curious how it changes the image colours. I don't have Firefox at the moment to test, can you upload a screenshot of what you get?
cxw-droid commented 7 months ago

Thank you for your reply.

  1. Yes, I use open with Firefox after right clicking a pdf file. Is it possible after I open a pdf file this way, then click some add-on button (like the doqment) to change its background color? Or you are using your own pdfjs in doqment and it is impossible to control the pdfjs backed pdf viewer from Firefox?
  2. There is another method trying to change the background color like this, but it seems filter does not work well to change the background color only. Is it possible to use other js code to achieve this?
  3. The image becomes black and white like this: image
shivaprsd commented 7 months ago

@cxw-droid

  1. Exactly! It is another restriction (😩) imposed by Firefox that extensions cannot modify the built-in pdfjs viewer (the reason cited being that the viewer is not a webpage but is a "part of Firefox" 🤷🏼‍♂️).
  2. This is what doqment does. 🙂 The point is you have to do this while the PDF is rendered, because after render it is just a raster image, i.e. just pixels. The filter technique you linked only inverts the pixels (in fact there is a filter-only option in doqment too, it is the last color swatch in the panel).
  3. Aha! That is technically not an image, but a vector shape. Probably shapes are drawn with the same colors as the text when pdfjs.forcePageColors is on (again in doqment you can control this from the expanded panel). If you open a PDF with an actual photograph the image colors would be rendered as normal I expect.
shivaprsd commented 3 months ago

Closing as answered.