HTMLViewer with embedded PDF not resizing automatically in Desktop 2025 (works in 2023)

Hello,

I’ve migrated a desktop project from Xojo 2023 to 2025. In the 2023 version, an HTMLViewer with all Lock properties set to True would automatically zoom an embedded PDF to fit the control when the window was resized.

In the 2025 version, the HTMLViewer still resizes, but the PDF inside it no longer scales. It keeps its original size.

This behavior changed without any code modification. I’ve tried using ExecuteJavaScript to force a resize, but it doesn’t replicate the smooth, automatic “fit-to-window” behavior of the previous version.

Did anyone else experience this? Any ideas on how to restore the old functionality?

Thank you.

Are you just setting the HTMLViewer to the PDF document, or are you providing any HTML to wrap it?

If it is just PDF then it is down to the web browsers PDF handling system to decide how to show it.

If you are happy to place some HTML in the viewer you can specify styles for the PDF container, forcing it to stretch to fit the width of the browser.

I load de htmlViewer with a pdf folderItem

htmlFactura.LoadPage(fileFactura)

I’ve tried with:

htmlFactura.ExecuteJavaScript("document.querySelector('embed').style.width = '100%'; document.querySelector('embed').style.height = '100%';")

and

htmlFactura.ExecuteJavaScript("document.querySelector('embed').style.zoom = 'fit-page';")

on DocumentComplete event with no luck.

If I run htmlFactura.LoadPage(fileFactura) on resize event it works, but I don’t like it, it’s a waste of resources

What platform?

The issue with the javascript is that the browser likely isn’t using an embed tag to place the PDF.

Even if it was using one the problem is the pdf doesn’t size to fill the embed tag, at least not in tests on the mac. There is little control over the way the PDF renderer works within the HTMLViewer. Perhaps one of the plugin vendors has a better solution. You can try solutions out in here. Put the HTML below in and press the run button. Resizing the right panel fails to make the PDF widen.

<!DOCYYPE html>
<html>
  <head>
    <style>
      embed {width:100%;height:100%}
    </style>
  </head>
  <body>
    <embed src="https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf" type="application/pdf">
  </body>
</html>

The PDF Viewer from GraffitiSuite does allow you to Fit Width from your code. So you could do that from the shown event of the viewer.

1 Like

MacOs, didn’t try on windows yet.

What I don’t understand is what changed from v2023 to v2025 that affects this in such a particular way

Likely a different underlying browser control version for HTMLVewer. Did you check across v2023 to v2025 for this ?

HTMLViewer on macOS uses the Webkit engine that is the basis for Safari. Changes in that engine would easily account for this change, without Xojo doing a thing to change anything. I’m pretty sure Xojo doesn’t event distribute the webkit engine along with macOS applications, like it did with Windows. It simply relies on OS libraries.

If you place the HTML I provided into Safari you will find that the web browser works in the exact same fashion that you are now finding HTMLViewer to suffer. In other words changing the overall document width does not cause the PDF document within the page to change width also.

Indeed. Okay then, pretty clear. Thank you, that’s good to know.

Best regards.