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

Free Support Forum - aspose.com

Cocatenating PDFs and getting PDF Head Signature is not found

Greetings,

I have code that uses Aspose.Words, Aspose.PDF, and Aspose.PDF.Kit to convert multiple word docs to pdf, merge the word docs and existing PDF's into one file, and upload that file to SharePoint. This is done based on the user selecting the docs to convert via Infopath/Forms Server.

If I select multiple Word docs for the process it works fine.

If I select multiple PDF docs it works fine.

If I select Word and PDF I get the PDF Head Signature is not found error. I was on the forum that I should set the memory stream position to 1, but this did not help.

Any help would be appreciated. Here is the code:

switch (docType)

{

case "DOC":

binFile = item.File.OpenBinary();

outputStream = ConvertWordDoc(binFile);

pdfList[docNumber] = outputStream;

docNumber = docNumber + 1;

break;

case "PDF":

binFile = item.File.OpenBinary();

Stream memStream = new MemoryStream(binFile);

pdfList[docNumber] = memStream;

docNumber = docNumber + 1;

break;

default:

break;

}

private MemoryStream ConvertWordDoc(byte[] wordDoc)

{

MemoryStream memStream = new MemoryStream(wordDoc);

Aspose.Words.Document srcDoc = new Aspose.Words.Document(memStream);

srcDoc.SaveOptions.ExportImagesFolder = "d:\temp";

// Save the DOC file as Aspose.Pdf.Xml in memory.

MemoryStream xmlDoc = new MemoryStream();

srcDoc.Save(xmlDoc, Aspose.Words.SaveFormat.AsposePdf);

xmlDoc.Position = 0;

// Read the document into Aspose.Pdf.

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(xmlDoc, null);

MemoryStream outputStream = new MemoryStream(100);

pdf.Save(outputStream);

// Instruct Aspose.Pdf to delete temporary image files.

pdf.IsImagesInXmlDeleteNeeded = true;

return memStream;

}

and for the merge...

PdfFileEditor pdfEditor = new PdfFileEditor();

Aspose.Pdf.Pdf outPdf = new Aspose.Pdf.Pdf();

outPdf.Title = _NextLibName.ToString();

MemoryStream finalDoc = new MemoryStream(100);

outPdf.Save(finalDoc);

for (int i = 0; i < pdfList.Length; i++)

{

pdfList[i].Position = 0;

}

pdfEditor.Concatenate(pdfList,finalDoc);

Hi,

Thank you for considering Aspose.

1. Since the "finalDoc" is also a source to be merging, please add the "finalDoc" to the input steam array "pdfList", and then make a new blank stream as output. (please refer to http://www.aspose.com/documentation/file-format-components/aspose.pdf.kit-for-.net-and-java/aspose.pdf.kit.pdffileeditor.concatenate_overload_4.html)

2. Please try Aspose.Pdf.Kit v3.0 in which a bug of "bad signature" is fixed.

Thanks,