为什么我与使用PDFBox的普通打印完全不同?

时间:2014-05-20 11:51:32

标签: java apache pdf printing pdfbox

我有一个问题是使用PDFBox打印PDF文件。它与普通打印完全不同。 我实现了一个java程序来打印PDF。

PDFPageable pdfPageable =new PDFPrinter(document).getPageable();
printerJob.setPageable(pdfPageable);
printerJob.print(printRequestAttributeSet);

我不确定为什么我与普通打印完全不同?

2 个答案:

答案 0 :(得分:0)

使用PDFBox jar快照缝合你的。我看到他们经常发布。我认为你最好与Dev支持团队沟通并完成它。接缝是一个渲染问题。

答案 1 :(得分:-1)

试试这个(改编自java api

中的示例
  import java.io.*;
  import javax.print.*;
  import javax.print.attribute.*; 
  import javax.print.attribute.standard.*;  

 public class PrintTest{

  public static void main(String args[]){

    FileInputStream psStream = null;
    try {
        psStream = new FileInputStream("some.pdf");
        } catch (FileNotFoundException ffne) {
          ffne.printStackTrace();
        }
        if (psStream == null) {
            return;
        }
    DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc myDoc = new SimpleDoc(psStream, psInFormat, null);  
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);

    // this step is necessary because I have several printers configured
    PrintService myPrinter = null;
    for (int i = 0; i < services.length; i++){
        System.out.println("service found: "+svcName);
        String svcName = services[i].toString();           
        if (svcName.contains("printer closest to me")){
            myPrinter = services[i];
            System.out.println("my printer found: "+svcName);
            break;
        }
    }

    if (myPrinter != null) {            
        DocPrintJob job = myPrinter.createPrintJob();
        try {
        job.print(myDoc, aset);

        } catch (Exception pe) {pe.printStackTrace();}
    } else {
        System.out.println("no printer services found");
    }
   }
  }