Free Support Forum - aspose.com

Concatenate several pdf documents

Hello,
How can we concatenate several pdf documents and save result as pdf ?

I’m using Visual Studio 2003 and C#.

Hi,

The feature is supported in the kit well, sample code about this applicant is showed here.

Thanks for your request.

Thank you,

Here if we cannot know the the number of files to concatenate (that is return by function FileNumber).

These method cannot work because :


Stream[] inStreams = new Stream[]{inStream1,inStream2,inStream3,inStream4};

pdfEditor.Concatenate(inStreams,outStream);


Concatenate takes does not takes twoo argments?

How can we perform this ?

Dear,

The current kit can’t support the feature directly, but you can use the Arraylist to buffer all pdf files, and copy the Arraylist to the target Stream array, then call the Concatenate.

If necessary, or you feel that it’s not convenient, the kit will support the feature soon.

Thank you,

What we want is to concatenate pdf files where the numbers of files to copy is returned by a function.

How can we use the Arraylist to buffer n pdf files, and copy the Arraylist to the target Stream array ?.

Do you have an example please !!!

Hi,
I don't understand all the context of your application, so the sample code is based on my imagination, I hope it's useful,

string inFile1 = "../test1.pdf";
string inFile2 = "../test2.pdf";
string outFile = "../test_out.pdf";
ArrayList myList = new ArrayList();
Stream[] streams;
FileStream inStream1 = new FileStream(inFile1, FileMode.Open, FileAccess.Read);
FileStream inStream2 = new FileStream(inFile2, FileMode.Open, FileAccess.Read);
myList.Add(inStream1);
myList.Add(inStream2);//other streams can be added continuely.

streams = new Stream[myList.Count];
myList.CopyTo(streams,0);

FileStream outStream = new FileStream(outFile,FileMode.Create);
PdfFileEditor editor = new PdfFileEditor();
editor.Concatenate(streams, outStream);
outStream.Close();

Thank you,
We consider a context with several files and the number of files is unknown.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />



string[] inFiles=new string[nmax];

// And then I put on inFiles my pdf files ( test1.pdf, test2.pdf,........, testn.pdf )

string outFile = "../test_out.pdf";
ArrayList myList = new ArrayList();
Stream[] streams;

// here how can I dynamically declare inStream1, inStream2,......., inStreamn.

// the number n is returned by a function, then we cannot know n when we are coding.


FileStream inStream1 = new FileStream(inFile1, FileMode.Open, FileAccess.Read);
FileStream inStream2 = new FileStream(inFile2, FileMode.Open, FileAccess.Read);
myList.Add(inStream1);
myList.Add(inStream2);//other streams can be added continuely.

streams = new Stream[myList.Count];
myList.CopyTo(streams,0);

FileStream outStream = new FileStream(outFile,FileMode.Create);
PdfFileEditor editor = new PdfFileEditor();
editor.Concatenate(streams, outStream);
outStream.Close();



Regards.

Hi,

.......
ArrayList myList = new ArrayList();
Stream[] streams;
FileStream inStream;

foreach(string inFile in inFiles)
{
inStream = new FileStream(inFile,FileMode.Open, FileAccess.Read);
myList.Add(inStream);
}

streams = new Stream[myList.Count];
myList.CopyTo(streams,0);

FileStream outStream = new FileStream(outFile,FileMode.Create);
PdfFileEditor editor = new PdfFileEditor();
editor.Concatenate(streams, outStream);
outStream.Close();

Thank you, but I’ve errors,

Concatenate no takes 2 parameters.
Error at :



editor.Concatenate(streams,outStream);



Regards

Hi,

Please download the latest kit.