Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unique and global viewOnLoad? #11496

Closed
hexleyOlive opened this issue Jan 10, 2020 · 1 comment
Closed

unique and global viewOnLoad? #11496

hexleyOlive opened this issue Jan 10, 2020 · 1 comment
Labels

Comments

@hexleyOlive
Copy link

I've similar problems and need describes here #11359.

The default reload behavior of the pdf.js viewer is indeed to preserve the scroll position (and some other GUI states) if the file is exactly the same.
The scroll position is keep only if the document ID embedded in a PDF file is the same, even if the PDF is strictly the same (except ID).

So, i looking for a workaround about this PDF ID and try to keep the last position view for ALL PDF.
Is it possible to overwrite the default reload behavior of the pdf.js viewer to keep the last position view regardless IDs of PDFs?
Goal is to have a unique and global "viewOnLoad" to reuse the last position for all PDFs.

Thanks

@hexleyOlive hexleyOlive changed the title common viewOnLoad? unique and global viewOnLoad? Jan 10, 2020
@hexleyOlive
Copy link
Author

hexleyOlive commented Jan 13, 2020

I finally found a way to preserve a unique scroll and zoom position for all PDF, i describe the solution here in case some else needs this:

In pdf.worker.js, need to modify the fingerprint key and hash value.
Search lines below:
key: "fingerprint", get: function get() {

The line above should be:
var hash;

define a fix value hash md5 var, i.e.:
var hash = '826ad6b0338304c40b42644b5144f80a';

Then comment lines above.
This part retrieve the ID of the PDF, in my case I would ignore this part.
//var idArray = 'this.xref.trailer.get('ID')';
// if (Array.isArray(idArray) && idArray[0] && (0, _util.isString)(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
// hash = (0, _util.stringToBytes)(idArray[0]);
// } else {
// hash = (0, _crypto.calculateMD5)(this.stream.getByteRange(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
// }

After these modification, you can add manually (dev mode) this extension to Chrome and keep the same position for all PDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants