首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印PDF双面打印

打印PDF双面打印
EN

Stack Overflow用户
提问于 2017-07-07 21:42:54
回答 1查看 885关注 0票数 0

我使用PDFBox打印PDF。遇到一些打印机在PrinterJob Sides.DUPLEX中发送时不能打印双面打印的问题,但是,如果发送准备好的PCL或PS文件,这些打印机可以打印双面打印。我在这里找到了这样一个链接Duplex Printing of PDF document with T&C at the Back ,作者创建了一个第三方ps文件,并在其中添加了一个双工文件。我想知道PDFBox是否可以直接将双工添加到输出流中。或者可能有一些替代的PDFBox,能够在打印时添加双面打印。

代码语言:javascript
复制
import java.awt.print.PrinterJob;
import java.io.File;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Sides;


import org.apache.pdfbox.pdmodel.PDDocument;

import org.apache.pdfbox.printing.PDFPageable;


public class PrintPDFMain
{

    public static void main(String args[]) throws Exception {


         try
         {
        File file ;
        int qty;
        if (args.length < 2)
         {
         System.out.println("1st param File 2nd param printer name 3rd param qty of copies 4th param duplex (yes/no) \n1st and 2nd params are mandatory");
         return; 
         }
        file = new File(args[0]);
        if  (!file.exists()) return;
        PDDocument document = PDDocument.load(file);

        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

        if (args.length > 2)
        {

            if (args.length >= 3) 
            {
                qty = 1;
                try
                {
                qty = Integer.parseInt (args[2]);
                }
                catch (NumberFormatException e)
                {
                    qty = 1;
                }
                System.out.println(qty);
             pras.add(new Copies(qty));
            }
            if (args.length >=4 )
            { 
                if (args[3].length() == 3 ) {System.out.println(args[3]); pras.add(Sides.DUPLEX);}}
        }


        PrinterJob job = PrinterJob.getPrinterJob();
              job.setPageable(new PDFPageable(document));
       job.print(pras);

      System.out.println("print");
       System.out.println();


    }
         catch (Exception e)
         {
             System.out.println("error " + e);
         }
    }





}
EN

回答 1

Stack Overflow用户

发布于 2017-07-08 19:44:37

经过彻底检查后,我发现系统中检测到的打印机是不带双面打印器的型号。重新安装驱动程序后,一切正常。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44972340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档