我正在尝试开发一种方法来控制报告数据的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.
如果你真的需要在每一页上都添加那个logo,说实话,JMP 19本身是做不到的。我最终采取的方法是分两步:先让JMP生成PDF,然后再运行一个简单的脚本,把logo添加到每一页上——用Python配合pypdf或reportlab,几行代码就能搞定整个文件夹。虽然不太美观,但非常可靠,而且一旦配置好,你甚至都感觉不到它的存在。
简而言之:JMP 19 在数据处理方面表现出色,提供了不错的页眉/页脚和页面布局,以及在第一页添加徽标——但不支持单页图片,也无法通过脚本控制字体。如果您坚持每页都要添加徽标,那就让 JMP 生成 PDF,然后再添加徽标,而不是像我一样费尽心思地在 JMP 里强行添加。