【发布时间】:2014-09-19 14:26:55
【问题描述】:
我尝试使用 DocPrintJob 打印 pdf,但它不适合页面,因此我必须手动打印页面。 我的 pdf 已经是 Letter 格式。
这是我到目前为止所做的:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(), 200, 200,
printService, defaultService, flavor, pras);
if (service != null) {
pras.add(MediaSizeName.NA_LETTER);
PageFormat page = new PageFormat();
/* MediaSizeName media = MediaSize.findMedia(
(float) (page.getWidth() / 72.0),
(float) (page.getHeight() / 72.0),
Size2DSyntax.INCH);
*/
// pras.add(media);
DocPrintJob job = service.createPrintJob();
FileInputStream fis=null;
File file = new File("test.pdf");
try {
fis = new FileInputStream("test.pdf");
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
DocAttributeSet das = new HashDocAttributeSet();
Doc document = null;
document = new SimpleDoc(fis, flavor, null);
try {
job.print(document, pras);
} catch (PrintException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
如您所见,我尝试使用 MediaSizeName.NA_LETTER,但它并没有改变任何东西。 有没有办法让用户选择媒体尺寸,打印对话框中没有选项? 提前致谢!
【问题讨论】: