使用pdfbox在letter us size上打印A4 doc

时间:2013-12-19 10:09:22

标签: printing pdfbox

我想在使用美国信纸的打印机上打印使用A4格式创建的PDF文档。

首先,我的方法是在A4格式的打印机上打印文档。

        public static void printWithPdfBox(String strFilename) throws IOException, PrinterException
        {

            PrinterJob job = PrinterJob.getPrinterJob();
            System.out.println("Printer name : "+ job.getPrintService().getName());
            PDDocument doc = new PDDocument();
            doc = PDDocument.load(strFilename);

            PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
            attributes.add(Sides.ONE_SIDED);

            job.setPageable(new PDPageable(doc, job));
            job.print(attributes);
        }

我尝试添加此属性但不起作用:

attributes.add(MediaSizeName.NA_LETTER);

在印刷方法的帮助下,提到:

  

请注意,可以通过等效方法调用(例如),副本:setcopies(int),作业名称:setJobName(String)直接在PrinterJob上设置某些属性,并通过PageFormat对象指定介质大小和方向。

如果有人有解决方案,我会帮助他们; o)

0 个答案:

没有答案