我正在通過調整以前編寫的桌面程序來打印拼圖,爲家庭成員創建打印拼圖。我需要每個拼圖以特定尺寸打印,在這種情況下是5平方英寸,我似乎找不到可以可靠編程的方法。使用通過反覆試驗來確定一個比例係數。這是用Clojure寫的,但我一點也被任何人誰使用Java可以理解的。特定尺寸的JavaFX打印節點
(defn create-print-button-click-handler
"Handle a click on the 'Print...' button."
[canvas stage]
(reify EventHandler
(handle [this event]
(if false
(batch-print)
;; else
(let [job (PrinterJob/createPrinterJob)]
(if (.showPrintDialog job stage)
(let [printer (.getPrinter job)
job-settings (.getJobSettings job)
;; Margin settings are in points. Set to half inch left margin,
;; 3/4 inch for the rest.
layout (.createPageLayout printer Paper/NA_LETTER PageOrientation/PORTRAIT
36.0 54.0 54.0 54.0)
printable-width (.getPrintableWidth layout)
printable-height (.getPrintableHeight layout)
printer-dpi (.getFeedResolution (.getPrintResolution job-settings))
dots-across (* printer-dpi 5) ;; five inches
cnvs (Canvas. dots-across dots-across)
scale 0.25]
(.setPrintColor job-settings PrintColor/MONOCHROME)
(.setPageLayout job-settings layout)
;; Scale by the same amount along both axes.
(.add (.getTransforms cnvs) (Scale. scale scale))
;; This ugliness is because I want to print the background completely white.
;; Since we are using the same function to draw the board to the screen and
;; to the canvas for printing, we need to change the background before
;; drawing then back afterwards.
(def board-color (Color/web "#ffffff"))
(redraw-board cnvs)
(def board-color (Color/web board-web-color))
(.printPage job cnvs)
(.endJob job))))))))
我見過一些例子使用的打印寬度和高度,但我沒有得到可理解的結果(太大,不適合頁)。
就像我說的,這個工程,但我想要的程序m以正確響應,當其他打印機使用時可能有不同的分辨率,不同的水平和垂直分辨率等