ngx-extended-pdf-viewer icon indicating copy to clipboard operation
ngx-extended-pdf-viewer copied to clipboard

Text dissapears when using the pdf viewer in a separate window

Open Yasmin-van-Dijk opened this issue 1 year ago • 3 comments

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

  • 19.2.0

Yasmin-van-Dijk avatar May 22 '24 08:05 Yasmin-van-Dijk

I am also running into this in v20.

luke-rogers avatar May 22 '24 14:05 luke-rogers

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

stephanrauh avatar May 22 '24 19:05 stephanrauh

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.

luke-rogers avatar May 22 '24 19:05 luke-rogers

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.

Yasmin-van-Dijk avatar May 24 '24 07:05 Yasmin-van-Dijk

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

stephanrauh avatar May 26 '24 18:05 stephanrauh

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

Yasmin-van-Dijk avatar May 28 '24 08:05 Yasmin-van-Dijk

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

stephanrauh avatar May 29 '24 19:05 stephanrauh

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.

  • The problem occurs in the worker thread. However, even by forcing the worker to run in the main thread, I couldn't see any error message, nor a failing file access, nor an exception.
  • Using a custom assets path seems to confuse the viewer. Using the standard /assets path makes a difference. However, I wouldn't call it progress: instead of showing boxes it renders an empty page.
  • However, if you're using a Japanese file loading the font definition from the external file assets/cmaps/Adobe-Japan1-UCS2.bcmap, the viewer worked flawlessly in the window. It's possible to use different zoom settings, and the file renders correctly.

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 avatar May 29 '24 20:05 stephanrauh

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.

stephanrauh avatar May 29 '24 20:05 stephanrauh

Hi Stephan,

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

Yasmin-van-Dijk avatar May 30 '24 07:05 Yasmin-van-Dijk