HTMLViewer and print

Is it possible to print a HTMLViewer in portrait, rather than landscape?

Thanks

Terry

Sorry, I should have said landscape rather than portrait.

Thanks

Terry

Set your PrinterSetup … to Landscape (Portrait by default).

Edit:

And if you want to always print Landscape, you have to save the PrinterSettings string (read the PrinterSetup LR page)

I don’t believe that HTMLViewer respects the page setup dialog box.

If you know how to print HTMLViewer in Landscape a very short example would be greatly appreciated.

Thanks

Terry

Have you simply tried to set landscape in the printer setup ?

This does not work:

  Dim settings as String
  Dim p as PrinterSetup
  p=New PrinterSetup
  If p.PageSetupDialog Then
    settings=p.SetupString
  End If
  p.MaxHorizontalResolution=300
  p.MaxVerticalResolution=300
  p.Landscape=True
  
  myHTMLViewer.Print

Mac? Win?

We have a couple of functions in our MBS Plugins.

For Mac check this class:

http://www.monkeybreadsoftware.net/class-webprintmbs.shtml

I have figured out it is possible but I have had to revert to some AppleScript to do it.

I am quite new to XOJO and am a little surprised this could not be done with XOJO coding.

Anyone?

Thanks

Terry

use framework "Foundation"
--use framework "Cocoa"
--use framework "AppKit"
use scripting additions

on run {}
	set tResult to pageSetup()
	return tResult
end run

on pageSetup()
	
	-- Calling an Objective-C class method:
	
	set tPageLayout to current application's class "NSPageLayout"'s pageLayout
	
	set tButtonClicked to tPageLayout's runModal as integer
	
	if tButtonClicked = 0 then
		set tResult to "cancel"
	else if tButtonClicked = 1 then
		set tResult to "ok"
	else
		set tResult to "error"
	end if
	
	return tResult
	
end pageSetup

If you send the HTML to a wkHTMLToPDF helper app it can accept a parameter for Landscape and Portrait. You can then either print the PDF or export it for the user to do with what they want. Run this shell:

<ShellPath to wkHTMLToPDF> --page-size A4 --load-error-handling ignore --enable-smart-shrinking --orientation Landscape '" + <HTML URLPath> + "' " + <pdfDestination ShellPath>

Note: on Windows remove the ‘–enable-smart-shrinking’ and for the PDF use NativePath rather than ShellPath.

On OS X (El Capitan), Xojo 2016r3:

[code] Dim settings As String
Dim p As PrinterSetup
Dim f As FolderItem

f = GetOpenFolderItem(“text/html”)
If f <> Nil Then
HTMLViewer1.LoadPage(f)

Else
Return False
End If

p = New PrinterSetup

p.Landscape = True

If p.PageSetupDialog Then
settings=p.SetupString
End If

p.MaxHorizontalResolution=300
p.MaxVerticalResolution=300

HTMLViewer1.Print // in Print to PDF mode, I get several pages, white pages…[/code]

In the Printer Setup dialog, play with the option and you will see one that propose to rotate the pronting. This set the page in Landscape, but the code above print only white pages (to PDF), so I cannot say more.

Here is my solution using Declare.

  declare function NSClassFromString lib "Foundation" (aClassName as CFStringRef) as Ptr
  declare function pageLayout  lib "AppKit" selector "pageLayout"(classRef as Ptr) as Ptr
  declare function runModal  lib "AppKit" selector "runModal"(classRef as Ptr) as Integer
  
  dim NSPageSetupRef as Ptr = NSClassFromString("NSPageLayout")
  dim pageLayoutInstance as Ptr = pageLayout(NSPageSetupRef)
  dim keyPressed As Integer = runModal(pageLayoutInstance)
  
  msgbox(str(keyPressed))
  
  myHTMLViewer.print()

Terry