レポートデータのPDF出力を制御する方法を開発しようとしています。ヘッダーとフッターの書式設定を制御し、ロゴを埋め込む機能を持たせたいと考えています。これを実現するにはどうすれば良いでしょうか?何か良いアイデアがあれば教えてください。
ああ、ついさっきJMP 19で複数ページのPDFレポートを作成するのに苦労したばかりなので、私が経験したような面倒なことはあなたにはさせないようにしてあげましょう。
率直に言って、ある程度のコントロールはできるものの、期待するほどではない。私のように痛い目に遭ってから気づくよりは、最初からそのことを知っておいた方が良いだろう。
For headers and footers, you've got Set Print Headers(left, center, right) and Set Print Footers(...) to match — three little text slots each. They take plain text plus some handy tokens, so "Page &pn; of &pc;" dropped in the right footer slot gives you "Page 1 of 5" and so on. Works great. But here's what got me: they're テキストのみ, and you can't set the font size in the script at all — it secretly follows the "Small" font role tucked away in File ▸ Preferences ▸ Fonts. Took me forever to realize that's why my footer wouldn't shrink. And if you try to stack two lines in one slot, watch out — the \!N newline thing the docs mention straight-up didn't work on my JMP 19 build and silently nuked the entire header. No error, just gone.
Page setup itself is actually solid, no complaints there. Set Page Setup(margins(...), scale(n), portrait(0), paper size("Letter")) handles orientation, margins, scaling, all fine. Just remember to tack on Save PDF(path, Show Page Setup(0)) — that little Show Page Setup(0) shuts off the print dialog popup, which you'll really want once you're cranking out a stack of these unattended.
厄介なのはロゴの部分です。ヘッダーとフッターはテキストのみなので、ロゴをそこに配置することはできません。そのため、すべてのページにロゴを表示する組み込みの方法はありません。有効な方法は、レポート本文に画像ボックスとして挿入し、base64形式で直接埋め込むことです。そうすれば、別の画像ファイルを持ち運ぶ必要がなくなります。
<SPAN>Picture Box( New Image( Char To Blob( logoB64, "base64" ), "png" ) )</SPAN>
Park that at the top of your outer V List Box and boom, you've got a letterhead — but page 1 only, 'cause the body just renders wherever it lands.
もし本当にすべてのページにロゴが必要なら、正直に言うと、JMP 19 単体ではできません。結局私がやったのは2段階の手順です。まず JMP で PDF を出力し、その後、簡単なスクリプトを実行してすべてのページにロゴを挿入します。Python と pypdf または reportlab を使えば、フォルダ全体に数行のコードで済みます。見た目は良くありませんが、非常に安定していて、一度設定してしまえば、その存在すら忘れてしまうほどです。
要するに、JMP 19はデータ処理に優れており、適切なテキストヘッダー/フッターとページ設定、さらに1ページ目にロゴを挿入できる機能も備えていますが、ページごとの画像挿入やスクリプトからのフォント制御は一切できません。もしすべてのページにロゴを入れることがどうしても譲れない条件であれば、私のようにJMP内で無理やりすべてを実装しようと頭を悩ませるよりも、JMPでPDFを作成して後からロゴを挿入する方が賢明でしょう。