allefeld / atom-pdfjs-viewer

Themed, fully featured PDF viewer for the Atom editor
MIT License
12 stars 3 forks source link

Remember zoom level between reloads #3

Closed ddbrierton closed 4 years ago

ddbrierton commented 4 years ago

I’ve been using pdfjs-viewer for a few days now, and so far very happy with it.

I have one feature request though. I’m using pdfjs-viewer to preview LaTeX documents from within Atom. I have the zoom level set to “page width”. When I build my LaTeX document after making some edits, the PDF is always reloaded at zoom level “automatic zoom”. With the way my Atom panes are configured the PDF is too small to read comfortably at “automatic zoom” and I have to manually change the zoom level back to “page width”.

Would it be possible for pdfjs-viewer to remember the zoom level between reloads?

allefeld commented 4 years ago

Glad you like it!

I suspect along with the zoom level you also see a scrolling back to the top of the document?

If so, then that's a feature of pdf.js, which makes up the largest part of the functionality of my package. pdf.js remembers the zoom level and scroll position based on the PDF's ID, which LaTeX generates based on the current time and date. Therefore, to pdf.js, after each compilation there is a new PDF, and the zoom and scroll position from the "other" PDF don't apply.

Since my package only wraps pdf.js, I'm not able to change this behavior.

In my own pandoc-pdf package which uses LaTeX, I set the environment variable SOURCE_DATE_EPOCH which is respected by LaTeX to the same value for every recompilation, so that the PDF ID stays the same and pdf.js does not reset zoom & scroll position.

If you run LaTeX manually, you could do something like that yourself. If you use another package / wrapper / etc., you could ask its authors to implement this.

ddbrierton commented 4 years ago

Ah, very interesting Carsten. So that gave me just enough info to find a solution. See the accepted answer to this:

https://tex.stackexchange.com/questions/229605/reproducible-latex-builds-compile-to-a-file-which-always-hashes-to-the-same-va

There wasn’t a solution for XeLaTeX, but there was for LuaLaTeX so I just switched to that and added this line to my doc preamble:

\pdfvariable suppressoptionalinfo \numexpr512\relax

and it all works perfectly.

allefeld commented 4 years ago

Great!