HTMLViewer scaling

I use HTMLViewer to display .PDF and .XPS files. HTMLViewer does not automatically scale the page. It is always displayed full size, though Ctrl- and Ctrl+ allow for zooming. Is it possible to zoom programmatically? Or, can I mimick the Ctrl+ and Ctrl- keys?

Thanks.

I remember reading something for HTML which used javascript. Of course now search leads to nothing.

I found a way, though, to zoom in. Project download below.

  • Insert a Container Control in the project
  • Add to it an HTMLViewer
  • Add method to the CC to load the URL

Sub LoadURL(URL as string) HTMLViewer1.LoadURL(URL) End Sub

  • Add methods to increase the size of the HTMLViewer and center it, and the same to decrease it :

[code]Sub plus()
HTMLViewer1.Width = HTMLViewer1.Width1.10
HTMLViewer1.Height = HTMLViewer1.height
1.10
if HTMLViewer1.Width > self.Width then
HTMLViewer1.Left = -(HTMLViewer1.width-self.width)/2
HTMLViewer1.top = -(HTMLViewer1.height-self.height)/2
elseif self.Width > HTMLViewer1.Width then
HTMLViewer1.Left = (self.width-HTMLViewer1.width)/2
HTMLViewer1.top = (self.height-HTMLViewer1.height)/2
end if
End Sub

Sub moins()
HTMLViewer1.Width = HTMLViewer1.Width/1.10
HTMLViewer1.Height = HTMLViewer1.height/1.10
if HTMLViewer1.Width > self.Width then
HTMLViewer1.Left = -(HTMLViewer1.width-self.width)/2
HTMLViewer1.top = -(HTMLViewer1.height-self.height)/2
elseif self.Width > HTMLViewer1.Width then
HTMLViewer1.Left = (self.width-HTMLViewer1.width)/2
HTMLViewer1.top = (self.height-HTMLViewer1.height)/2
end if
End Sub
[/code]

  • Add the Container Control to the window, plus two buttons + and - with in each a call to the methods to increase and decrease the size.

When run, + zooms in and - zooms out :slight_smile:

Project

It works perfectly on my Mac.

Unfortunately, on Windows 8.1, for some reason, I was never able to load any PDF into an HTMLViewer :frowning:
With Native renderer, it wants to open in the default browser or save the file, and with WebKit, nothing…

You mention you are viewing PDF with HTMLViewer on your system, so I hope the attached project works fine.

You could use setfocus to the htmlviewer and then use a SendKeys() methods to programmatically send the ctrl+/- to the htmlviewer.

https://forum.xojo.com/6009-sendkey-function/0

That’s right. You can sendkeys to your own window.

Much simpler than what I do. Excellent idea.

I looked into SendKeys but I can’t find the keycode for Ctrl- and Ctrl+… any idea? I tried to look it up by checking what Xojo reports with AsyncKey but it doesn’t respond. And how to send it to your own Window?

Michel thanks for your enthousiastic answer. I will look into SendKeys though.

[Edit] I found the way to send Ctrl etc, and it does send keys but I can’t receive them in my Window. Do I have to specify a handle or something?

[quote=89383:@Alexander van der Linden]I looked into SendKeys but I can’t find the keycode for Ctrl- and Ctrl+… any idea? I tried to look it up by checking what Xojo reports with AsyncKey but it doesn’t respond. And how to send it to your own Window?

Michel thanks for your enthousiastic answer. I will look into SendKeys though. [/quote]

I understand. I realized only after posting that I did not manage scrolling :frowning: It would require a lot more work.

I have already successfully used the code posted by John Hansen in the thread Matthew Combatti indicated.

The way Sendkeys work is by sending keys to a window present on the screen by its title. So if your window is entitled “My Application”, you will go :

[code]wsh.AppActivate(“My Application”)

or

wsh.AppActivate(self.Title)[/code]

As Matthew said, do not forget to set focus to the HTMLViewer before you use the method.

Mmmm… my HTMLViewer is not in a ContainerControl,. I use this code:

dim wsh as new OLEObject("WScript.Shell") wsh.AppActivate(self.Title) XPSViewer.setfocus wsh.SendKeys("^+")

But it looks like the HTMLViewer does not receive focus. As I use the standard buttons manually with Ctrl+ I have to click inside the window before it responds…

[quote=89385:@Alexander van der Linden]Mmmm… my HTMLViewer is not in a ContainerControl,. I use this code:

dim wsh as new OLEObject("WScript.Shell") wsh.AppActivate(self.Title) XPSViewer.setfocus wsh.SendKeys("^+")

But it looks like the HTMLViewer does not receive focus. As I use the standard buttons manually with Ctrl+ I have to click inside the window before it responds…[/quote]

So your HTMLViewer is simply added to the window, right ? I will experiment on my side and see how I can get that working.

You know what I would appreciate a lot ? Could you post a small sample project that load a pdf into the HTMLViewer. I have been incapable to this day to ever have this working. It is staring to bug me…

You can also send to mitchboo a t gmail . com . Thank you.

I use XPS files… which is the Microsoft equivalent of PDF… I’ll send you a demo

I shall generate XPS and see how it goes, then. Thanks. I have tried the XPS printer long ago and wanted to add documentation in that format to my software when it was released with XP I think, but then got discouraged when for some reason Windows requested to pay the reader. But that was so long ago. Maybe since then MS realized that XPS had to be free to succeed.

Demo on its way…
To be honest… XPS loads very fast into the HTMLViewer… it has small footprint, limited capabilities compared to PDF (no buttons, hyperlinks etc.), but is is free and fast! Adobe Reader has become bloatware.

[quote=89395:@Alexander van der Linden]Demo on its way…
To be honest… XPS loads very fast into the HTMLViewer… it has small footprint, limited capabilities compared to PDF (no buttons, hyperlinks etc.), but is is free and fast! Adobe Reader has become bloatware.[/quote]

All Adobe software suffers from pathological obesity :wink:

No luck.

Sendkeys works fine sending to its own window.I added keydown to the window and a msgbox to show the key received, it works quite fine.

The issue is with HTMLViewer. If I try HTMLViewer.SetFocus not only the control does not get the focus, but the IDE takes over like there was an error but shows nothing, and the app becomes frozen.

The problem with HTMLViewer seems even worse : keydown simply does not fire. I tried clicking in it and then typing a key, no keydown event.

I am sorry, but I do not see what to do right now. If the control is incapable to receive keydown events, it means the way it reacts to ctrl- and ctrl+ is coded otherwise, probably through direct access to the keyboard scan codes.

Matthew, your idea was excellent, but it simply does not work :frowning:

I found back the javascript method I new I has seen before. It is at https://forum.xojo.com/10925-html-scaling-for-webhtmlviewer but unfortunately does not work for PDF and XPS :frowning: Only HTML.

Now I may have to go back to the drawing board and add scroll bars to the Container Control subclass I posted before. It is possible, just a little less convenient than the SendKeys method.

Basically, as long as the user does not zooms in, the regular scrollbars can be used. When he zooms in, the regular scroll bars are covered and new ones must then appear that take over.

HTMLViewer is such a black box, though, it is not so easy to know the length of the document it contains. I will have to figure that.

Too bad Monkeybread HTMLViewer class exist only for Mac. It would have been great in this instance.

For windows:

Instead of using the HTMLViewer you can also use adobe Reader with use of a OLEContainer.

This will only works if you have adobe Reader installed
Simple Example:

add a OLEContainer to window1 (OLEContainer1)
Right mouse click on OLEContainer1
Select "Choose ActiveX Control..." (Small window appears with list of Activex Controls)
Select from Displayed window "Adobe PDF Reader" (This will assign a ProgramID to OLEContainer1)
  1. Add following code in Pushbutton1.action:
  OLEContainer1.Content.src = "c:\\MyFile.pdf"
  OLEContainer1.show
  1. Add following code in Pushbutton2.action:
OLEContainer1.Content.SetZoom(200)   //Zoom 200 percent

It works perfectly :slight_smile: That is more than I can say for HTMLViewer where I have never seen any PDF load on Windows, webkit or not…

Brilliant.

I had to install Adobe Reader, and discovered that they install Mac Afee together without any consent from the user. Pushy pushy :confused:

[quote=89581:@John Hansen]For windows:

Instead of using the HTMLViewer you can also use adobe Reader with use of a OLEContainer.

This will only works if you have adobe Reader installed
Simple Example:

add a OLEContainer to window1 (OLEContainer1)
Right mouse click on OLEContainer1
Select "Choose ActiveX Control..." (Small window appears with list of Activex Controls)
Select from Displayed window "Adobe PDF Reader" (This will assign a ProgramID to OLEContainer1)
  1. Add following code in Pushbutton1.action:
  OLEContainer1.Content.src = "c:\\MyFile.pdf"
  OLEContainer1.show
  1. Add following code in Pushbutton2.action:

OLEContainer1.Content.SetZoom(200) //Zoom 200 percent [/quote]

If you want to see all Methods and properties that is supported for ActiveX Component: Adobe PDF Reader

Do Following in Xojo:

  1. Select in top Menu: Insert --> ActiveX Component… (Com Components Window Displayed)
  2. Select Tab folder Controls in Com Components Window
  3. Select “Adobe PDF Reader” in Controls Window

In the Navigator you will now see following: a AcroPDF OLEContainer and a AcroPDFLib Module

  1. Mouse click on the “AcroPDF” OLEContainer to expand the tree

Here you have the Methods and properties that is supported for “Adobe PDF Rerader”

[quote=89630:@Michel Bujardet]It works perfectly :slight_smile: That is more than I can say for HTMLViewer where I have never seen any PDF load on Windows, webkit or not…

Brilliant.

I had to install Adobe Reader, and discovered that they install Mac Afee together without any consent from the user. Pushy pushy :/[/quote]

Strange I always see a check box before you download Adobe PDF Reader, you have to uncheck if you not want to have MaCaFee Installed

code related…

HtmlViewer1.ZoomTextIn
HtmlViewer1.ZoomTextOut

[quote=326649:@nicolscanessa]code related…

HtmlViewer1.ZoomTextIn
HtmlViewer1.ZoomTextOut

That does not work for Windows.