문제

I have a problem adding already existed pdf into current pdf I just generated. I saw PdfCopy but my situation is a little different. I have a pdf on the fly which is generated right now and before sending it out to the client I need to add an existing pdf into it.

도움이 되었습니까?

해결책

If you don't mind losing all interactivity that might be present in the existing PDF, you can use PdfReader and PdfImportedPage. Please start by reading the documentation, more specifically section 6.2.1 entitled "Importing pages". You can also download the example ImportingPages1 or take a look at this code snippet:

PdfReader reader = new PdfReader(existing_pdf);
PdfImportedPage page = writer.getImportedPage(reader, pagenumber);
document.setPageSize(reader.getPageSize(pagenumber));
document.newPage();
PdfContentByte canvas = writer.getDirectContent();
canvas.addTemplate(page, 0, 0);

This snippet is written from memory. You may need to tweak it here and there if it doesn't work immediately.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top