Free Support Forum - aspose.com

Problem concatenating documents

Hi, currently I´m trying to concatenate multiple documents (word and pdf documents) into a single pdf document using the PdfFileEditor class. Here is my code:


public byte[] CreatePDF(Dictionary<string, byte[]> documents)
{
byte[] result;
List memoryFiles = new List();

foreach(string documentName in documents.Keys)
{
string[] nameParts = documentName.Split(’.’);
string documentFormat = nameParts[nameParts.Length - 1];
MemoryStream pdfMemoryStream =null;

switch (documentFormat.ToUpper())
{
case “DOCX”:
MemoryStream docxMemoryStream = new MemoryStream(documents[documentName]);
Aspose.Words.Document wordDocument = new Aspose.Words.Document(docxMemoryStream);
SaveFormat saveFormat = SaveFormat.Pdf;
pdfMemoryStream = new MemoryStream();
wordDocument.Save(pdfMemoryStream, saveFormat);
docxMemoryStream.Close();
docxMemoryStream.Dispose();
break;
case “PDF”:
byte[] documentBytes = documents[documentName];
pdfMemoryStream = new MemoryStream(documentBytes);
break;
}

memoryFiles.Add(pdfMemoryStream);
}

PdfFileEditor pdfFileEditor = new PdfFileEditor();
using (MemoryStream pdfResult = new MemoryStream())
{
pdfFileEditor.Concatenate(memoryFiles.ToArray(), pdfResult);
result = pdfResult.ToArray();
}

foreach (MemoryStream memoryFile in memoryFiles)
memoryFile.Dispose();

return result;
}

Even the original documents are ok but the resulting concatenated file have at the end of each page a strange characters. Is there anything wrong with the code?

I put as an attachments the documents and the concatenated file.

Thank you.

Hi Mauricio,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample file.

It seems that you are not using Aspose.Pdf license in your application. The strange characters in the bottom are basically the evaluation message (shown in reverse). Please use a valid license of Aspose.Pdf and it will remove the evaluation message from your concatenated file. As you are using both Aspose.Words for .NET and Aspose.Pdf for .NET, you need to add the license code for both products in your application separately. To apply the license of Aspose.Pdf for .NET, you may check the following documentation links:

Using File or Stream object

Using as Embedded resource

I also tried to replicate the issue without using a license but I am not able to see the evaluation message in reverse (it is always on top of the concatenated PDF file). As some variables and methods are missing from your code, I would request you to create a sample application so we can identify the cause of this reverse evaluation message and fix it.

Please feel free to contact support in case you need any further assistance.

Sorry for the inconvenience,

Ok, now I see the evaluation message. Your right, I was licencing the Aspose Word and I forgot about the Aspose Pdf.


Thank you.

Hi Mauricio,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the confirmation regarding the resolution of your issue. Please feel free to contact support in case you need any further assistance.

Thank You & Best Regards,