spring脚i文字错误
spring boot i text errror
大家好我有一个现有的 pdf 文件,其中包含 facture body 我想向这个 facture 添加文本,我制作了一个测试代码来测试它是如何工作的,但是我写的代码删除了我的原始文件,结果添加的文本
private static final String FILE_PATH_NAME = "./src/main/resources/educart.pdf";
public void exportpdf(facture fact) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(new File(FILE_PATH_NAME)));
//open
document.open();
// Paragraph 1 ->
Paragraph p = new Paragraph("This is a paragraph 1",
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC));
document.add(p);
// Paragraph 2 ->
Paragraph p2 = new Paragraph();
p2.add("This is a paragraph 2");
p2.setAlignment(Element.ALIGN_CENTER);
document.add(p2);
// Paragraph 3 ->
Font f = new Font();
f.setStyle(Font.BOLD);
f.setSize(30);
f.setColor(255, 0, 0);
Paragraph p3 = new Paragraph("This is a paragraph 3", f);
p3.setAlignment(Element.ALIGN_RIGHT);
document.add(p3);
// Paragraph 4 ->
Paragraph p4 = new Paragraph("Grokonez",
FontFactory.getFont(FontFactory.HELVETICA, 250, Font.BOLDITALIC));
document.add(p4);
// Finish task ->
document.close();
System.out.println("Finish!");
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
}
原始pdf文件
结果
PdfReader pdfReader =
new PdfReader("./src/main/resources/educart.pdf");
//Create PdfStamper instance.
PdfStamper pdfStamper = new PdfStamper(pdfReader, out);
大家好我有一个现有的 pdf 文件,其中包含 facture body 我想向这个 facture 添加文本,我制作了一个测试代码来测试它是如何工作的,但是我写的代码删除了我的原始文件,结果添加的文本
private static final String FILE_PATH_NAME = "./src/main/resources/educart.pdf";
public void exportpdf(facture fact) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(new File(FILE_PATH_NAME)));
//open
document.open();
// Paragraph 1 ->
Paragraph p = new Paragraph("This is a paragraph 1",
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC));
document.add(p);
// Paragraph 2 ->
Paragraph p2 = new Paragraph();
p2.add("This is a paragraph 2");
p2.setAlignment(Element.ALIGN_CENTER);
document.add(p2);
// Paragraph 3 ->
Font f = new Font();
f.setStyle(Font.BOLD);
f.setSize(30);
f.setColor(255, 0, 0);
Paragraph p3 = new Paragraph("This is a paragraph 3", f);
p3.setAlignment(Element.ALIGN_RIGHT);
document.add(p3);
// Paragraph 4 ->
Paragraph p4 = new Paragraph("Grokonez",
FontFactory.getFont(FontFactory.HELVETICA, 250, Font.BOLDITALIC));
document.add(p4);
// Finish task ->
document.close();
System.out.println("Finish!");
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
}
原始pdf文件
结果
PdfReader pdfReader =
new PdfReader("./src/main/resources/educart.pdf");
//Create PdfStamper instance.
PdfStamper pdfStamper = new PdfStamper(pdfReader, out);