PDFBOX打印:打印的PDF包含来自PDF的阿拉伯文本的垃圾字符 [英] PDFBOX Printing : Printed PDF contains Junk characters for Arabic text from the PDF

查看:143
本文介绍了PDFBOX打印:打印的PDF包含来自PDF的阿拉伯文本的垃圾字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含阿拉伯文字和水印的PDF文件.我正在使用PDFBox从Java打印PDF.我的问题是PDF的打印质量很高,但是所有带有阿拉伯字符的行都带有垃圾字符.有人可以帮忙吗?

I have a PDF file containing Arabic text and a watermark. I am using PDFBox to print the PDF from Java. My issue is the PDF is printed with high quality, but all the lines with Arabic characters have junk characters instead. Could somebody help on this?

代码:

    String pdfFile = "C:/AresEPOS_Home/Receipts/1391326264281.pdf";
    PDDocument document = null;
    try {
    document = PDDocument.load(pdfFile);
    //PDFont font = PDTrueTypeFont.loadTTF(document, "C:/Windows/Fonts/Arial.ttf");
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setJobName(new File(pdfFile).getName());
    PrintService[] printService = PrinterJob.lookupPrintServices();
    boolean printerFound = false;
    for (int i = 0; !printerFound && i < printService.length; i++) {
        if (printService[i].getName().indexOf("EPSON") != -1) {
            printJob.setPrintService(printService[i]);
            printerFound = true;
        }
    }
    document.silentPrint(printJob);
    } 
    finally {

      if (document != null) {
     document.close();
      }
}

推荐答案

本质上

可以使用PDFBox 2.0.0-SNAPSHOT正确打印您的PDF,但不能使用PDFBox 1.8.4正确打印.因此,有问题的阿拉伯字体需要的功能在1.8.4版本之前的PDFBox中尚不支持,或者1.8.4中的错误已得到修复.

In essence

Your PDF can properly be printed using PDFBox 2.0.0-SNAPSHOT but not using PDFBox 1.8.4. Thus, either the Arabic font in question requires a feature which is not yet supported in PDFBox up to version 1.8.4 or there was a bug in 1.8.4 which meanwhile has been fixed.

使用PDFBox 1.8.4打印OP的文档会导致类似这样的混乱输出

Printing the OP's document using PDFBox 1.8.4 resulted in some scrambled output like this

但是使用当前的PDFBox 2.0.0-SNAPSHOT打印该文件会得到这样的正确输出

but printing it using the current PDFBox 2.0.0-SNAPSHOT resulted in a proper output like this

在2.0.0-SNAPSHOT中,PDDocument方法printsilentPrint已被删除,因此原来的

In 2.0.0-SNAPSHOT the PDDocument methods print and silentPrint have been removed, though, so the original

document.silentPrint(printJob);

必须替换为

printJob.setPageable(new PDPageable(document, printJob));
printJob.print();

这篇关于PDFBOX打印:打印的PDF包含来自PDF的阿拉伯文本的垃圾字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆