Webview.print([settings]) method


Prints the current top-level document in the WebView using optional programmatically specified print settings to a printer.

Parameters

[settings]

An optional table that may contain any of the following keys :
  • "orientation": contains a string value to indicate page orientation among "landscape" and "portrait" (the default).
  • "pageHeight": contains a number value to indicate page height in inches.
  • "pageWidth": contains a number value to indicate page width in inches.
  • "header": contains a boolean value to indicate if the header is printed (defaulting to true).
  • "background": contains a boolean value to indicate if the the background is printed (defaulting to false).
  • "colorMode": contains a string value to indicate color mode, "grayscale" or "color" (the default).
  • "copies": contains a number value to indicate the number of copies to be printed (defaulting to 1).
  • "scaleFactor": contains a number value to indicate the scale factor (defaulting to 1).
If this parameter is not provided, a dialog will show for the user to configure the print settings.

Return value

If the function is called without settings argument :

This function returns a boolean value (the call will block current execution, with the print settings dialog).

If the function is called with settings argument :

This function will return a Task instance. Once finished, this Task will return :

  • A boolean indicating if the operation succeeded
  • In case of error, a string representing the error message is returned as a second return value

Example

local ui = require "ui" require "webview" local win = ui.Window("Chrome Devtools Protocol example", "fixed", 640, 480) local wv = ui.Webview(win, 0, 0, 640, 440) local button = ui.Button(win, "Print the web page !") button:center() button.y = 446 win:center() function button:onClick() wv:print() end function wv:onReady() self:loadstring([[ <!DOCTYPE html> <html> <body> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam. Maecenas ligula massa, varius a, semper congue, euismod non, mi. Proin porttitor, orci nec nonummy molestie, enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper </body> </html>]]) end ui.run(win):wait()