2021年2月22日月曜日

【解決】 WEBビューアが印刷できない。プレビューモードで表示されない。- FIleMaker

WEBビューアが印刷できない。プレビューモードで表示されない。- FIleMaker

Windows, macOS 対応。iOS(FileMaker Go)は、非対応。

Chart.js が印刷できないとか、Google Map が印刷できないとか、
WEBビューアをキャプチャして画像として保存したい場合に使用。

GoogleChrome でWEBビューアに表示されている内容をキャプチャして印刷で使用する。

WebViewerCaptureChrome.fmp12
動作検証:
FileMaker:16,17,18,19
Windows 10, macOS:10.15.6, 10.13.6
Windows:Powershell使用(Windows標準インストール)
macOS:AppleScript使用(macOS標準インストール)

サンプルファイル

※サンプルファイルは、高解像度キャプチャ対応
https://fm-aid.stores.jp/items/60327a4e2438607fc668027c

使用方法

WebViewerCaptureChrome.fmp12 を開く

画面右上の[⚙(歯車)]アイコンをクリック。
Google Chrome のパスを設定。(Chromeのインストール先を変更していなければそのままでOK)
※Google Chrome のパスは、アドレスバーに chrome://version/ と入力で確認できます。
例:
Windows:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
macOS:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

-

ExampleWebViewerCaptureChrome.fmp12 を開く


「WebViewer DATA or SOURCE」に URL または、HTML を入力。

「capture[object]」ボタンでキャプチャしたpng画像(実データ)が取得できます。

「capture[path]」ボタンでキャプチャしたpng画像をファイルパスが取得できます。
※png画像はテンポラリフォルダに保存されています。

WEBビューアの式 例:

プレビュー・印刷モードの時は、キャプチャした画像を表示。
キャプチャした画像は、パスがあればその画像を優先、なければオブジェクトフィールドの画像を表示。 となっています。
詳しくは、サンプルファイル:ExampleWebViewerCaptureChrome.fmp12 を参照

/*
フィールド値が、URL,file,<HTML>どれでも表示
プレビュー・印刷モードの時は、キャプチャした画像を表示
キャプチャした画像は、パスがあればその画像を優先、なければオブジェクトフィールドの画像を表示
*/
Let([
¢mode=Get (ウインドウモード)
;¢DATA=Let(
¢source=Trim(WVCaptureChrome::WebViewerDATAorSOURCE)
;
Case ( Left ( ¢source ; 1 ) = "<" ; "data:text/html;charset=utf-8,"; "" ) & ¢source
)
;¢CPath=WVCaptureChrome::CapturePath
;¢CObj=WVCaptureChrome::CaptureObj
;¢html=
"data:text/html,
<html>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='initial-scale=1.0' />
<style>
* {border:0; margin:0px; padding:0px;overflow:hidden;}
img {
object-fit: cover;
}
</style>
</head>
<body>
<img src='{src}' onLoad='this.style[this.width>this.height?\"width\":\"height\"]=\"100%\"'>
</body>
</html>"
];
Case ( ¢mode=2 or ¢mode=3 ;
Case (
not IsEmpty ( ¢CPath ) ; Substitute ( ¢html ; "{src}" ; "file://" & ¢CPath );
not IsEmpty ( ¢CObj ) ; Substitute ( ¢html ; "{src}" ; "data:image/png;base64," & Base64Encode ( ¢CObj ) );
¢DATA
);
¢DATA
)
)


既存ファイルからの利用方法

外部データソースに「WebViewerCaptureChrome.fmp12」を登録。

ファイル -> 管理 -> 外部データソース


新規 をクリックし「WebViewerCaptureChrome.fmp12」を選択

[OK]をクリックで登録完了。


スクリプト例: キャプチャした画像を取得

スクリプト名:Capture[object]

#{"source":"https://fm-aid.com/bbs2/viewforum.php?id=2","width":"300","height":"300"}
変数を設定 [ $source; 値:WVCaptureChrome::WebViewerDATAorSOURCE ]
変数を設定 [ $width; 値:GetLayoutObjectAttribute ( "WEB01" ; "width" ) ]
変数を設定 [ $height; 値:GetLayoutObjectAttribute ( "WEB01" ; "height" ) ]
変数を設定 [ $json; 値:Let([¢json="" ;¢json=JSONSetElement ( ¢json ; "source" ; $source ; 1 ) ;¢json=JSONSetElement ( ¢json ; "width" ; $width ; 1 ) ;¢json=JSONSetElement ( ¢json ; "height" ; $height ; 1 ) ]; ¢json ) ]
スクリプト実行 [ 「Capture(json)」 , ファイル: 「WebViewerCaptureChrome」; 引数: $json ]
フィールド設定 [ WVCaptureChrome::CaptureObj; Get(スクリプトの結果) ]

引数(json)を作成し、「WebViewerCaptureChrome.fmp12」のスクリプト:Capture(json) を実行

引数:
{
"source":"HTML または、URL",
"width":"キャプチャする横幅",
"height":"キャプチャする縦の長さ"
}

例:
{
"source":"https://fm-aid.com/bbs2/viewforum.php?id=2",
"width":"300",
"height":"300"
}

スクリプト例: キャプチャした画像のパスを取得

スクリプト名:Capture[path]

#引数 例: {"ReturnType":"path","source":"https://fm-aid.com/bbs2/viewforum.php?id=2","width":"300","height":"300"}
#"ReturnType"が、 path のときスクリーンショットイメージのパスを返す
変数を設定 [ $ReturnType; 値:"path" ]
変数を設定 [ $source; 値:WVCaptureChrome::WebViewerDATAorSOURCE ]
変数を設定 [ $width; 値:GetLayoutObjectAttribute ( "WEB01" ; "width" ) ]
変数を設定 [ $height; 値:GetLayoutObjectAttribute ( "WEB01" ; "height" ) ]
変数を設定 [ $json; 値:Let([¢json="" ;¢json=JSONSetElement ( ¢json ; "ReturnType" ; $ReturnType ; 1 ) ;¢json=JSONSetElement ( ¢json ; "source" ; $source ; 1 ) ;¢json=JSONSetElement ( ¢json ; "width" ; $width ; 1 ) ;¢json=JSONSetElement ( ¢json ; "height" ; $height ; 1 ) ]; ¢json ) ]
スクリプト実行 [ 「Capture(json)」 , ファイル: 「WebViewerCaptureChrome」; 引数: $json ]
フィールド設定 [ WVCaptureChrome::CapturePath; Get(スクリプトの結果) ]

引数(json)を作成し、「WebViewerCaptureChrome.fmp12」のスクリプト:Capture(json) を実行

"ReturnType":"path" を指定で、キャプチャした画像のパスを返します。

引数:
{
"ReturnType":"path",
"source":"HTML または、URL",
"width":"キャプチャする横幅",
"height":"キャプチャする縦の長さ"
}

例:
{
"ReturnType":"path",
"source":"https://fm-aid.com/bbs2/viewforum.php?id=2",
"width":"300",
"height":"300"
}

0 件のコメント:

コメントを投稿