Webview:printPDF(settings)method
Generate a PDF file from the current top-level document in the WebView using optional programmatically specified print settings.
Parameters
Parameters
settings
Atable that may contain any of the following keys :"file": a filename as astringor File (this field is required)."orientation": contains astringvalue to indicate page orientation among"landscape"and"portrait"(the default)."pageHeight": contains anumbervalue to indicate page height in inches."pageWidth": contains anumbervalue to indicate page width in inches."header": contains abooleanvalue to indicate if the header is printed (defaulting totrue)."background": contains abooleanvalue to indicate if the the background is printed (defaulting tofalse)."colorMode": contains astringvalue to indicate color mode,"grayscale"or"color"(the default)."copies": contains anumbervalue to indicate the number of copies to be printed (defaulting to1)."scaleFactor": contains anumbervalue to indicate the scale factor (defaulting to1).
Return value
This function will return a Task instance. Once finished, this Task will return :
- A
booleanindicating if the operation succeeded - In case of error, a
stringrepresenting the error message is returned as a second return value
Example
--! luart-extensions
import ui
require "webview"
local sysutils = require "sysutils"
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 to PDF !")
button:center()
button.y = 446
win:center()
function button:onClick()
local success, result = await(wv:printPDF {file = "test.pdf" })
if not success then
ui.error(result)
else
sysutils.shellexec("open", "test.pdf")
end
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
await win:showasync()