- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 pdfbox 打印现有的 pdf 文件。目前我正在通过 maven 使用 pdfbox 2.0.0 RC3。
这是我当前的代码:
PDDocument document = PDDocument.load(new File(myPdfFile));
PrinterJob job = PrinterJob.getPrinterJob();
if (job.printDialog()) {
job.setPageable(new PDFPageable(document));
job.print();
}
document.close();
为了进行测试,我用 Adobe Acrobat 打印了一个测试 pdf,并用几行代码打印了同一个 pdf。除了边框,一切正常。所有边框(页眉、页脚、左侧和右侧)都太小,页脚太小。
有没有我在万维网上找不到的设置正确缩放比例/格式的神奇方法?
最佳答案
试试这个 pdfbox 2.0.0-RC3 版本
PDDocument doc = PDDocument.load(new File("test.pdf"));
PDFPrintable printable = new PDFPrintable(doc, Scaling.SHRINK_TO_FIT);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
job.print();
这是另一个版本
PDDocument doc = PDDocument.load(new File("test.pdf"));
PrinterJob job = PrinterJob.getPrinterJob();
// define custom paper
Paper paper = new Paper();
paper.setSize(306, 396); // 1/72 inch
paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); // no margins
// custom page format
PageFormat pageFormat = new PageFormat();
pageFormat.setPaper(paper);
// override the page format
Book book = new Book();
// append all pages
book.append(new PDFPrintable(doc, Scaling.SHRINK_TO_FIT), pageFormat, doc.getNumberOfPages());
job.setPageable(book);
job.print();
关于java pdfbox printerjob错误的缩放/页面格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35479613/
我目前在使用默认打印机打印 jpeg 文件时卡住了。在我的程序中,当我从文件夹中选择图像时,我需要使用打印机默认设置(纸张尺寸、边距、方向)打印它。 目前我得到了这个: PrintService pr
我正在尝试打印一张发票(AnchorPane),其中包含许多包含发票信息的标签、GridPanes、VBox 等。除了缩放比例完全困惑之外,我只能打印随机字符而不是发票信息。 我很确定我遗漏了一些东西
我使用以下方法在我正在使用的程序中打印 pdf 文件。它有效,但每次我想要打印单个页面时都必须调用该方法。因此,如果我想将同一个文档打印五次,则整个方法必须执行五次。我的问题是,是否有某种方法可以将多
我需要为我的打印例程实现一个监听器,以便从打印机获取状态。我正在使用 PrinterJob,但监听器 PrintServiceAttributeListener 对我来说还不够。我想改为为 DocPr
我在使用 java 打印 PDF 时遇到问题。我知道 Java 本身不支持打印 PDF,因为 java 没有 PDF 渲染器。因此,为了解决这个问题,我使用了 PDFRenderer 库,下面是一个使
我正在尝试以 300 dpi 打印质量在 1 英寸 x 2 英寸标签上打印图像 public void print() { RepaintManager currentManager
我想要在 PrinterJob.pageDialog 中设置页面格式的选项,唯一缺少的是更改页面方向,因为横向模式的单选按钮被禁用。 问题是我不知道如何在此对话框中启用代表横向模式的单选按钮。仅当在打
我正在尝试通过 JavaFX 应用程序打印收据,但每当我尝试打印时都会收到 NullPointerException。 import javafx.print.PrinterJob; // More
通过调用不带任何参数的 PrinterJob 的 printDialog() 方法,我获得了用于更改打印作业属性的对话框。在该对话框的右下角有一个字段,用户可以更改要打印的份数。 现在我想禁用这个字段
美好的一天! 我目前正在开发一个需要将特定数据直接打印到打印机的程序。幸运的是,我已经用 Java 运行了 PrinterJob 和 Printable 实用程序。这是代码: SWFPrintable
我有一个使用 Java 8 (1.8.0_45) 在 Mac(OS X,el capitan)上开发的应用程序,可以打印到打印机。它可以很好地打印到打印机,在纸上画一个漂亮的圆圈(椭圆形)。但是,我已
我使用 PrinterJob 对象来打印我的 Bufferedimage,我有一个 BufferedImage,我对其进行处理并将其发送到具有纸张格式等的打印机作业,但我无法使其适合我的证卡打印机。当
PrinterJob 某人用来打印文件。 tif 或。争吵? . jpg。 png 它可以正常打印。但是文件。 Tif 不打印,它生成一个空白的 pdf。谁能告诉我我能做什么? public void
监听器是否可用于 java.awt.print.PrinterJob ?我只能找到 PrintJobListener在 javax.print.DocPrintJob .我正在 java.awt.pr
我遇到以下问题: 我们的 Swing 应用程序有一个超时,它会将用户返回到登录框架。 如果用户打开打印对话框并使其保持打开状态,然后在超时后尝试单击打印按钮,我们的应用程序将失败并向用户显示错误。 (
我正在尝试使用 PageFormat 信息在打印之前修改基于 javax.swing 的打印输出。我对如何从 PrintJob 获取 PageFormat(使用 getPrinterJob() 和 p
我正在使用 java.awt.print.PrinterJob.printDialog() 在 javafx 应用程序中启动 printDialog。在 os-x 上运行时,我总是从 printDia
尝试使用 Java 打印 PDF 文件时遇到问题。这是我的代码: PdfReader readFtp = new PdfReader(); // This class is used for r
我尝试了以下 AWT 代码,但在运行时重复显示多个打印对话框.... package printerjob; import java.awt.BasicStroke; import java.awt.
我正在使用 JavaFX PrinterJob 打印节点,如下所示: /** * @param node */ public static final void print(Node no
我是一名优秀的程序员,十分优秀!