stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 167 forks source link

Text dissapears when using the pdf viewer in a separate window #2340

Closed Yasmin-van-Dijk closed 1 month ago

Yasmin-van-Dijk commented 1 month ago

We use this pdf viewer in our Angular application to view pdf's in a separate window (using window.open)

Describe the bug

  1. Open the pdf viewer in a separate window
  2. Zoom or resize the window
  3. The text dissapears, squares are shown instead

Version info

luke-rogers commented 1 month ago

I am also running into this in v20.

stephanrauh commented 1 month ago

Is there any error message in the console? Does it happen with every PDF file, or are only certain PDF files affected?

luke-rogers commented 1 month ago

I also saw this happen on the Mozilla PDF viewer, so maybe it's a core bug.

If you interact, and do something like zooming then the PDF re renders and everything appears again.

Yasmin-van-Dijk commented 1 month ago

We don't have any error messages in the console when the text dissapears.

It does not happen with every pdf. We checked these pdf's in the Mozilla PDF viewer, there we did not have this issue.

stephanrauh commented 1 month ago

I'm not sure how to reproduce the bug. Can you send me a simple reproducer, please?

Yasmin-van-Dijk commented 1 month ago

Yes, I have created a simple Angular application with the pdf viewer in a pop out window: https://github.com/Yasmin-van-Dijk/demo-pop-out-pdf-viewer/tree/master

stephanrauh commented 1 month ago

I've downloaded your reproducer. Now I can reproduce your issue. Thanks!

stephanrauh commented 1 month ago

I'm afraid your issue required much more knowledge about pdf.js than I have. I can give you a few qualified guesses after debugging a few hours.

However, even with the Japanese file, the viewer was slightly broken in the window. Hitting the "+" and "-" buttons to modify the zoom setting resulted in weird jumps of the zoom level.

I suspect the viewer is ill prepared for loading its resources in one window and running the code in another window. To be honest, I'm surprised it's possible at all - I didn't expect that. Adding insult to injury, I believe it's a bug (or peculiarity?) of the base library, so I don't believe I'm able to fix it.

As a workaround, I suggest either using modal dialogs or using window.open() with the native viewer of the browser. Opening an <iframe> in the new browser should also work.

I'm sorry I can't provide a solution - but I believe this is one of the hard problems! I hope at least one of my workarounds suits you.

Best regards, Stephan

stephanrauh commented 1 month ago

I've closed the ticket, but I'm still listening to this channel. If you've got new insight, don't hesitate to tell me.

Yasmin-van-Dijk commented 1 month ago

Hi Stephan,

Thanks for looking into this! We will try your suggested workarounds.