如何使用itext 5附加PDF
我尝试将我的PDF附加到新的ITEXT文档中,但这是不可能的,我创建了我想要添加的文档。如何从文档级别执行此操作?需要以某种方式转换为字节吗如何使用itext 5附加PDF,pdf,append,itext,Pdf,Append,Itext,我尝试将我的PDF附加到新的ITEXT文档中,但这是不可能的,我创建了我想要添加的文档。如何从文档级别执行此操作?需要以某种方式转换为字节吗 String inputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700.pdf"; // Existing file String outputFilePath = "C:\\Users\\yol\\Deskt
String inputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700.pdf"; // Existing file
String outputFilePath = "C:\\Users\\yol\\Desktop\\90-B1-1C-91-7D-13\\historyPDF\\07-12-2019 01-10-36-700_new.pdf"; // New file
Document document = new Document();
OutputStream fos = new FileOutputStream(new File(outputFilePath));
PdfReader pdfReader = new PdfReader(inputFilePath);
PdfStamper pdfStamper = new PdfStamper(pdfReader, fos);
pdfStamper.insertPage(pdfReader.getNumberOfPages() + 1, pdfReader.getPageSizeWithRotation(1));
PdfContentByte pdfContentByte = pdfStamper.getUnderContent(pdfReader.getNumberOfPages());
pdfContentByte.beginText();
pdfContentByte.setFontAndSize(BaseFont.createFont
(BaseFont.TIMES_ROMAN,
BaseFont.CP1257,
BaseFont.NOT_EMBEDDED
)
, 12);
pdfContentByte.setTextMatrix(35, 760);
document.open();
Chapter chapter = new Chapter("", 0);
chapter.setNumberDepth(0);
Paragraph time = new Paragraph("");
Paragraph date = new Paragraph("");
Paragraph type = new Paragraph("");
chapter.add(time);
chapter.add(date);
chapter.add(type);
document.add(chapter);
pdfContentByte.endText();
document.close();
pdfStamper.close();
pdfReader.close();
不要试图一次做完所有的事。首先使用
文档
&PdfWriter
创建一个包含新内容的新PDF,并将其写入临时位置(文件系统或内存中)。然后使用新的文档
和PdfCopy
将所有要打包的文档合并到一个文档中。不要试图一次完成所有操作。首先使用文档
&PdfWriter
创建一个包含新内容的新PDF,并将其写入临时位置(文件系统或内存中)。然后使用新的文档
和PdfCopy
将所有要打包的文档合并到一个文档中。