Zoom not properly working when running as Web Component

WebViewer Version: 11.8.0

Do you have an issue with a specific file(s)?

  • no

Can you reproduce using one of our samples or online demos?
Yes, this one also just zooms to the center instead of the mouse location:

Are you using the WebViewer server?

  • no

Does the issue only happen on certain browsers?

Is your issue related to a front-end framework?

  • maybe, we are using vite + react

Is your issue related to annotations?

  • no

Please give a brief summary of your issue:
Pinch-to-zoom and CTRL+ Mouse wheel zoom doesn’t follow mouse location

Please describe your issue and provide steps to reproduce it:
Basically when trying to zoom into a pdf it will only zoom to a certain location (for us its the right side), ignoring the mouse position.
We would expect that it zooms to the mouse position. This is working without a problem when you render the Webviewer as an IFrame (WebViewer.Iframe). We would want to avoid going this route though.

We are using Resizable from Shadcn (Resizable - shadcn/ui) to render the pdf, this causes it to only zoom to the right hand side of a pdf.
Moving it out of the Resizable will follow the mouse a bit, but will still be off. It seems like the mouse position is not correctly tracked.

Minimal reproducible example with our stack:

<div className="w-300 h-200">
  <PDFViewer ... />
</div>
export const PDFViewer: FC<Props> = ({}) => {
  const viewer = useRef<HTMLDivElement>(null)

  const initializePDFViewer = useCallback(async () => {
    if (!viewer.current) return

    const instance = await WebViewer(
      {
        path: '/lib/webviewer',
        css: '/lib/webviewer/pdfViewerStyles.css',
        licenseKey: import.meta.env.VITE_WEBVIEWER_LICENSE_KEY,
        fullAPI: true,
        enableFilePicker: true,
        preloadWorker: WebViewer.WorkerTypes.PDF,
        enableOptimizedWorkers: true,
      },
      viewer.current
    )
  }, [])

  return <div className="w-full h-full relative" ref={viewer} />
}

Happy to also provide a video/more information if needed.

Thanks!

1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems like you’re experiencing an issue with the zoom behavior in the WebViewer when used as a Web Component, specifically related to mouse position tracking during zoom operations. This could be due to the Shadow DOM encapsulation affecting how mouse events are handled, especially when combined with third-party components like Shadcn’s Resizable.

Some things you can try:

  • Ensure that the WebViewer’s container element and the WebViewer itself are correctly sized and have appropriate CSS styles applied.

  • Check the event listener setup for mouse events to ensure they are being captured and processed correctly within the shadow DOM.

  • Consider using WebViewer’s API to manually control zoom behavior based on mouse events if the default behavior is not working as expected.

  • Test the zoom functionality without additional third-party components to isolate the issue and verify if Resizable is affecting the behavior.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

Hi Ed,

Thank you for reaching out.

I was able to reproduce a difference in behavior between Iframe and Webcomponent, and will add this issue to the backlog for the product team to review.

If you could provide some further information about the context and the importance of the issue to you, this may help prioritize its development. We would be interested to know:

  • What is the impact of the issue on you and your users?
  • How are you coping without it right now?

We will let you know when we have additional updates.

Best Regards,
Mickaël.

1 Like

Hi Mickaël!

Thanks for responding quickly!

What is the impact of the issue on you and your users?

  • Quite big to be honest. Our users review a lot of architectural plans that can get very complicated, so for them not being able to zoom to the right section of the document is quite painful. Especially older users are very confused by it.

How are you coping without it right now?

  • Haven’t really found a fix right now for the problem

Best,
Ed

1 Like

Hi Ed,

Thank you for your quick reply.

I’ve raised that information to the backlog team.
I will let you know when I have additional updates.

Best Regards,
Mickaël.

2 Likes

Hi Mickaël,

is there an update on this?

Thanks!

Best,
Ed

1 Like

Hi Ed,

The issue was accepted in the backlog, and the team will work on a fix for this, but there is no timeline for the moment.

Best Regards,
Mickaël.

1 Like