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

Free Support Forum - aspose.com

Use .Append() to build upon itself

I need to create a brand new PDF based upon pages from existing PDFs.

Example:
NEW PDF = all pages from PDF1, pages 1-3 from PDF2

I see two issues here:
1. How can I tell .Append() to start from scratch without providing an Input filename?
2. How can I tell .Append() to use the same Input and Output filename without causing a problem?

Here is my proposed code which still complains that Output file is stuck open so it can’t write to it:

'Create a new blank PDF file since there is no pdf.kit function to do this:
newFile = System.IO.File.Create(DestinationPDF)
newFile.Close()
for i=1 to number of PDFs
'Now append all the pages from other PDFs into it. But it doesn’t like opening DestinationPDF both for reading and writing:
asposePDF.Append(DestinationPDF, SomePDFArray(i), StartAtPage, EndAtPage, DestinationPDF)
next

Suggestions?
-Dave

Hi David,

Thank you very much for considering Aspose.

Please share the complete code snippet along with the sample PDF files, so we could share the issue at your end. I’m afraid, I can’t understand the problem completely from your post. I hope your code and the sample PDF files would help me understand and work on the issue.

We’re sorry for the inconvenience.
Regards,

This is pretty simple to explain. I need a NEW PDF file based upon pages of OTHER PDF files:


NewPDF.PDF = PDF1(Pages1-3) + PDF2(Pages1-3)

I cannot change PDF1 or PDF2 and NewPDF does not exist yet. It is a new construction based upon pages from PDF1 and PDF2.

I would like to use .Append() or something like that from pdf.kit.

-Dave

Hi David,

First of all, in order to append a file to another one, you can’t use the same file as input and output, or a stream for that matter. You’ll have to use two separate files or streams for input and output. The reason is that when append method is working both of these files are in use concurrently. So, if you’ll use the same file as input and output, it will definitely get stuck.

Moreover, at one time, you can append only one file to another file. So, if you have created an output stream and you would like to use it as input stream for your next operation, you’ll have to copy the stream from the output stream to the input stream. But, that would be your custom solution. Aspose.Pdf.Kit doesn’t provide this kind of solution out of the box.

Please have a look at Append method and an article at this link.

I hope this helps. If you still find any issues, please do let us know.
Regards,