Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2   11.3   11.4    Statistic    FMM    Blog  

WebView.PrintToFile

Prints the current web view content to PDF file.

Component Version macOS Windows Linux Server iOS SDK
WebView 4.0 ✅ Yes ❌ No ❌ No ❌ No ❌ No
MBS( "WebView.PrintToFile"; WebViewerRef; Path )   More

Parameters

Parameter Description Example
WebViewerRef Either the Web Viewer Object Name or the Web Viewer ID as returned by "WebView.FindByName" function.
Path Native file path where to save PDF. "/tmp/test.pdf"

Result

Returns OK or error.

Description

Prints the current web view content to PDF file.
You can get/set some parameters on macOS using the WebView.GetPrintParameter/WebView.SetPrintParameter functions.
Especially you can control whether to print background or not.

If needed you can import this PDF file with Files.ReadPDF into a container file.
See also WebView.RenderPDF.

Not supported for WebKit 2.x (FileMaker 16 Mac). We tried it, but as of macOS 10.12.4 we only get damaged files, crashes or white pages. Works in FileMaker 16 or later, when using a Web Viewer created using WebView.Create.

This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.

Examples

Create PDF and import it:

Set Variable [ $path ; Value: MBS( "Folders.UserDesktop" ) ]
Set Variable [ $path ; Value: MBS( "Path.AddPathComponent"; $path; "test.pdf" ) ]
Set Variable [ $r ; Value: MBS( "WebView.PrintToFile"; $$web; $path ) ]
Set Field [ Own WebView::Container ; MBS( "Files.ReadPDF"; $path) ]

Print via WebKit 1.x web viewer:

# Create WebViewer Copy in file WebViewer Print

# Create web view in version 1 for WebKit
Set Variable [ $$web ; Value: MBS("WebView.Create"; 0; 40; 80; 970; 440; 1) ]
# Load som eURL
Set Variable [ $r ; Value: MBS( "WebView.LoadURL"; $$web; "http://www.mbs-plugins.com") ]
# wait for website to load
Loop
    Exit Loop If [ MBS( "WebView.IsLoading"; $$web ) ≠ 1 ]
    Pause/Resume Script [ Duration (seconds): ,1 ]
End Loop
# set print parameters
Set Variable [ $r ; Value: MBS("WebView.SetPrintParameter"; "shouldPrintBackgrounds"; 0) ]
Set Variable [ $r ; Value: MBS("WebView.SetPrintParameter"; "leftMargin"; 30) ]
Set Variable [ $r ; Value: MBS("WebView.SetPrintParameter"; "topMargin"; 30) ]
Set Variable [ $r ; Value: MBS("WebView.SetPrintParameter"; "rightMargin"; 30) ]
Set Variable [ $r ; Value: MBS("WebView.SetPrintParameter"; "bottomMargin"; 30) ]
# get a file path
Set Variable [ $Path ; Value: MBS( "Path.AddPathComponent"; MBS( "Folders.UserDesktop" ); "test.pdf") ]
# print to PDF
Set Variable [ $r ; Value: MBS("WebView.PrintToFile"; $$web; $Path) ]

See also

Example Databases

Blog Entries

Created 18th August 2014, last changed 5th November 2020


WebView.PrintPreview - WebView.Release

Feedback: Report problem or ask question.