我正在通过调整以前编写的桌面程序来打印拼图,为家庭成员创建打印拼图。我需要每个拼图以特定尺寸打印,在这种情况下是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以正确响应,当其他打印机使用时可能有不同的分辨率,不同的水平和垂直分辨率等