对于 Java 程序,您输入的数据将被放入 PDF(PDF 中已有数据,程序中的数据应放入特定位置)。有没有办法做到这一点?
最佳答案
您可以使用Itext PDF来做到这一点在maven项目中。您可以添加以下功能来打印数据。
private static String FILE = "../print2.pdf";
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
//This is title.
Paragraph preface = new Paragraph();
addEmptyLine(preface, 1);
document.add(preface);
preface.add(new Paragraph("This is cupcake.", catFont));
addTitlePage(document);
// This is content.
Anchor anchor = new Anchor(AddSalesPromoController.tempPromoName.getText(), catFont);
anchor.setName("First Chapter");
document.close();
if (Desktop.isDesktopSupported()) {
try {
File myFile = new File("../print2.pdf");
Desktop.getDesktop().open(myFile);
} catch (Exception ex) {
ModelUtil.getAlert("Not supported", "not supported", Alert.AlertType.ERROR);
// no application registered for PDFs
}
}
} catch (Exception e) {
e.printStackTrace();
}
关于PDF 中的 Java 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077568/