ITextPdf

0

Maven

<dependency>
	<groupId>com.itextpdf</groupId>
	<artifactId>itextpdf</artifactId>
	<version>${itextpdf.version}</version>
</dependency>
<dependency>
	<groupId>com.itextpdf</groupId>
	<artifactId>itext-pdfa</artifactId>
	<version>${itextpdf.version}</version>
</dependency>
<dependency>
	<groupId>com.itextpdf</groupId>
	<artifactId>itext-xtra</artifactId>
	<version>${itextpdf.version}</version>
</dependency>
<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-imaging</artifactId>
	<version>1.0-alpha3</version>
</dependency>

添加附件

final PdfFileSpecification pdfFileSpecification = PdfFileSpecification.fileEmbedded(pdfWriter, filePath.toFile().getAbsolutePath(), title, null);
// 中文乱码
pdfFileSpecification.setUnicodeFileName(title, true);
pdfWriter.addFileAttachment(pdfFileSpecification);

添加视频

final PdfFileSpecification pdfFileSpecification = PdfFileSpecification.fileEmbedded(pdfWriter, filePath.toFile().getAbsolutePath(), title, null);
pdfFileSpecification.setUnicodeFileName(title, true);
pdfWriter.addFileAttachment(pdfFileSpecification);
final PdfAnnotation pdfAnnotation = PdfAnnotation.createScreen(pdfWriter, PAGE_SIZE, title, pdfFileSpecification, mime, false);
pdfAnnotation.setPage(pdfWriter.getPageNumber());
pdfWriter.addAnnotation(pdfAnnotation);