我正在嘗試開發一種方法來控制報告數據的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 裡強行添加。