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

Free Support Forum - aspose.com

Concatenate losing sequencing

I have 3 pdf’s I am attempting to concatenate in a very specific order. However when using the concatenate method the sequence in which I had them to the composite memory stream is not the same sequence in which I am getting them out. We are using Aspose.PDF.Kit v2.0.50727.

Attached are the documents I am trying to merge and are named in the sequence I want them back out as 1 pdf.

private FileContentResult GetAllDocuments(Snapshot snap)
{
byte[] fileLetter = snap.GetDocument(DocumentTypes.Letter);
byte[] fileABN = snap.GetDocument(DocumentTypes.ABN);
byte[] fileHINN1 = snap.GetDocument(DocumentTypes.HINN1);
byte[] retStream;
MemoryStream pdfOutStream = null;
List compsiteStream = new List();
Stream letterStream = null;
Stream abnStream = null;
Stream hinn1Stream = null;
Stream tempStream = null;

try
{

Aspose.Pdf.Kit.PdfFileEditor pdfEditor = new Aspose.Pdf.Kit.PdfFileEditor();
pdfOutStream = new MemoryStream();

if (fileLetter != null)
{
letterStream = new MemoryStream(fileLetter);
compsiteStream.Add(letterStream);
}
if (fileABN != null)
{
abnStream = new MemoryStream(fileABN);
}
if (fileHINN1 != null)
{
hinn1Stream = new MemoryStream(fileHINN1);
compsiteStream.Add(hinn1Stream);
}

pdfEditor.Concatenate(compsiteStream.ToArray(), pdfOutStream);

retStream = pdfOutStream.ToArray();

return File(retStream, “application/pdf”);
}
finally
{
if (letterStream != null) { letterStream.Close(); letterStream.Dispose(); }
if (abnStream != null) { abnStream.Close(); abnStream.Dispose(); }
if (hinn1Stream != null) { hinn1Stream.Close(); hinn1Stream.Dispose(); }
if (pdfOutStream != null) { pdfOutStream.Close(); pdfOutStream.Dispose(); }
pdfOutStream = null;
letterStream = null;
abnStream = null;
pdfOutStream = null;
}
}

Hi Adam,


Thanks for your inquriy. I am afraid you are using a quite old version of Aspose.Pdf.Kit for .NET. Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET had been merged into a single product since Aspose.Pdf for .NET 6.0.0. Aspose.Pdf.Kit for .NET had also been discontinued as a separate product. All the features of Aspose.Pdf.Kit for .NET are available under Aspose.Pdf.Facades namespace of Aspose.Pdf for .NET. Please check following documentation link for migrating from Aspose.Pdf.Kit for .NET to Aspose.Pdf for .NET.


Furthermore, I have tested your scenairo using Aspose.Pdf for .NET 11.1.0 and unable to noticed the reproted sequencing issue. Please download and try latest version of Aspose.Pdf for .NET, it will resolve the issue.

byte[] fileLetter = System.IO.File.ReadAllBytes(@“C:\Users\Home\Downloads\Document1 (2).pdf”);<o:p></o:p>

byte[] fileABN = System.IO.File.ReadAllBytes(@"C:\Users\Home\Downloads\Document2 (1).pdf");

byte[] fileHINN1 = System.IO.File.ReadAllBytes(@"C:\Users\Home\Downloads\Document3.pdf");

byte[] retStream;

MemoryStream pdfOutStream = null;

List<Stream> compsiteStream = new List<Stream>();

Stream letterStream = null;

Stream abnStream = null;

Stream hinn1Stream = null;

//output stream

FileStream outputStream = new FileStream(myDir + "CombinedDocument_output.pdf", FileMode.Create);

try

{

Aspose.Pdf.Facades.PdfFileEditor pdfEditor = new Aspose.Pdf.Facades.PdfFileEditor();

pdfOutStream = new MemoryStream();

if (fileLetter != null)

{

letterStream = new MemoryStream(fileLetter);

compsiteStream.Add(letterStream);

}

if (fileABN != null)

{

abnStream = new MemoryStream(fileABN);

compsiteStream.Add(abnStream);

}

if (fileHINN1 != null)

{

hinn1Stream = new MemoryStream(fileHINN1);

compsiteStream.Add(hinn1Stream);

}

pdfEditor.Concatenate(compsiteStream.ToArray(), outputStream);

//retStream = pdfOutStream.ToArray();

}

finally

{

if (letterStream != null) { letterStream.Close(); letterStream.Dispose(); }

if (abnStream != null) { abnStream.Close(); abnStream.Dispose(); }

if (hinn1Stream != null) { hinn1Stream.Close(); hinn1Stream.Dispose(); }

if (pdfOutStream != null) { pdfOutStream.Close(); pdfOutStream.Dispose(); }

pdfOutStream = null;

letterStream = null;

abnStream = null;

pdfOutStream = null;

}


Please feel free to contact us for any further assistance.


Best Regards,