We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add one pdf Document to another pdf Document

I’ve had no luck in figuring out how to do this in Java. I don’t think concatenating will work for me because I need to string together many different pdf documents into one, and writing an output file to the drive for each concatenation will be too inefficient (assuming I understand the process correctly). I am using the trial version of Aspose Pdf.

Hi Gary,


Thanks for your inquiry. Please check following documentation link, Aspose.Pdf concatenates the PDF files in memory and you can save final output to stream or disk. Furthermore, Document() ctor can also read PDF document from stream or disk. However, if there is any difference in my understanding and your requirement then please share some more details and sample code, so we will guide you accordingly.


Best Regards,

Thanks for the quick response. I figured this out before I got your response:

Document document_1 = new Document();
Document document_2 = new Document();
document_1getPages().add(document_2.getPages());

Is this as good a way to do it?

Thanks in advance.

Hi Gary,


Thank for your feedback. Yes, its fine. Please note for loading existing PDF documents you should pass PDF document via stream or file path to Document(stream/filepath) constructor. When you want to create a PDF from scratch then you use blank constructor and add Pages to it and proceed as per your need e.g convert an image to Pdf.

Document document_1 = new Document(stream/filepath);
Document document_2 = new Document(stream/filepath);
document_1.getPages().add(document_2.getPages());
document_1.save(filepath/stream);

Please feel free to contact us for any further assistance.

Best Regards,