引包:itext7全局桶:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.1.8</version>
<type>pom</type>
</dependency>
try (PdfReader reader = new PdfReader("a.pdf");
PdfWriter writer = new PdfWriter("b.pdf");
PdfDocument pdfDoc = new PdfDocument(reader, writer)) {
Document document = new Document(pdfDoc);
//设置样式
PdfFont font = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
//单位是px
float left = 350;
float bottom = 680;
float width = 100;
//设置字体的大小,加粗和具体位置
document.add(new Paragraph("REMINDER").setFont(font).setFontSize(18).setBold().setFixedPosition(1, left, bottom, width));
document.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}