首页 > 解决方案 > pdfbox 打印页面导致 IllegalArgumentException miter limit < 1

问题描述

我正在尝试使用 pdfbox v2.0.21 打印 PDF 文档,为此我使用以下代码:

PDDocument document = PDDocument.load(f);
PrintService myPrintService = findPrintService("Name of my printer");
                
PrinterJob job = PrinterJob.getPrinterJob();
PDFPageable pageable = new PDFPageable(document);
job.setPageable(pageable);
job.setPrintService(myPrintService);
job.print();

当将它与不同的示例 PDF 一起使用时,此代码可以正常工作,但我想打印一个我首先裁剪为仅显示页面特定部分的 PDF。

当我尝试打印裁剪的 PDF 时,出现错误

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: miter limit < 1

还有一个关于缺少字体的警告,如下所示:

[AWT-EventQueue-0] DEBUG org.apache.fontbox.ttf.PostScriptTable - No PostScript name information is provided for the font 

我没有找到很多关于斜接限制的信息,也许它可能与 PDF 文档中的裁剪有关,或者它可能与丢失的字体有关。任何有关我如何解决此主题的提示将不胜感激!

错误的堆栈跟踪如下所示:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: miter limit < 1
    at java.awt.BasicStroke.<init>(BasicStroke.java:201)
    at org.apache.pdfbox.rendering.PageDrawer.getStroke(PageDrawer.java:769)
    at org.apache.pdfbox.rendering.PageDrawer.strokePath(PageDrawer.java:812)
    at org.apache.pdfbox.contentstream.operator.graphics.StrokePath.process(StrokePath.java:37)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:933)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:515)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:489)
    at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
    at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:272)
    at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:431)
    at org.apache.pdfbox.printing.PDFPrintable.print(PDFPrintable.java:246)
    at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:2165)
    at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1547)
    at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1390)
    at my.function.shipping.view.Panel.printDocument(Panel.java:659)
    at my.function.shipping.view.Panel.actionPerformed(Panel.java:733)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

标签: javapdfbox

解决方案


它将在版本 2.0.22 中修复。在那之前,这里有一个快照可用。票是PDFBOX-5019


推荐阅读