Free Support Forum - aspose.com

Join Aspose PDF documents

Hello,

First of all sorry for my English.

I’m a consultant for one of yours customers in Italy that need to compile a lot of word document width aspose and then join all the document in a single PDF for download.

I tried width tow different solution:

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

1° solution

- generate all the document in aspose word format;

- join all the document with the my join function (the code is at the end of the message) using the xml pdf format;

- print save the pdf with the SaveAsPDF funcition (the code is at the end of the message).

2° solution

- generate all the document directly in PDF;

- join the document with PDF4NET library.

For the first solution the problem is the width more then tree document the SaveAsPDF don’t work (no exceptions but at the Save method the CPU go at 100% and stay for ever).

For the second solution the problem is in the PDF4NET library that throw an exception when I try to open the PDF document generated by Aspose.

I asked to PDF4NET team an the replay was:

“The problem you encoutered appears because of the PDF file you are using.

The PDF file (created by Aspose component) has several bugs in it. While

the

Adobe software is more relaxed and fault tolerant to PDF errors, the PDF4NET

library follows strictly the PDF specification. The problem is that several

structures in the PDF file have specified an invalid length, and when the

library reads the structure, it reads invalid data.”

Can you help me?

private XmlDocument JoinDocument(ArrayList docArray)

{

if (docArray.Count < 1)

{

throw new Exception ("Array di documenti vuoto");

}

Document doc1 = (Document)docArray[0];

MemoryStream stream1 = new MemoryStream();

doc1.Save(stream1, SaveFormat.FormatAsposePdf);

stream1.Seek(0, SeekOrigin.Begin);

XmlDocument xmlDoc1 = new XmlDocument();

xmlDoc1.Load(stream1);

XmlNodeList xnlInsertAfter= xmlDoc1.GetElementsByTagName("Section");

XmlNode xnInsertAfter = xnlInsertAfter.Item(0);

XmlNode root = xmlDoc1.DocumentElement;

for (int i=1; i< docArray.Count; i++)

{

Document doc2 = (Document)docArrayIdea;

MemoryStream stream2 = new MemoryStream();

doc2.Save(stream2, SaveFormat.FormatAsposePdf);

stream2.Seek(0, SeekOrigin.Begin);

XmlDocument xmlDoc2 = new XmlDocument();

xmlDoc2.Load(stream2);

XmlNodeList xnl= xmlDoc2.GetElementsByTagName("Section");

XmlNode xn = xnl.Item(0);

XmlElement elem = xmlDoc1.CreateElement("Section");

foreach (XmlAttribute attr in xn.Attributes)

{

XmlAttribute newAttr= xmlDoc1.CreateAttribute(attr.Name);

newAttr.Value=attr.Value;

elem.Attributes.Append(newAttr);

}

elem.InnerXml=xn.InnerXml;

root.InsertAfter(elem, xnInsertAfter);

xnInsertAfter=elem;

}

return xmlDoc1;

}

private void SaveAsPdf(XmlDocument xmlDoc)

{

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

pdf.IsImagesInXmlDeleteNeeded = true;

pdf.BindXML(xmlDoc, null);

MemoryStream pdfStream = new MemoryStream();

pdf.Save(@"D:\test.pdf");

}



Hi bazzani,

Thank you for considering Aspose.

1)For the first solution
The error is caused by Aspose.Word. Make sure you are using the latest hotfix of Aspose.Word. If you still can’t get it work, you can send your document to Roman and ask him to check it.

2)For the second solution
Please make sure you are using the latest hotfix of Aspose.Pdf since I have fixed some bugs which cause merging error. If you still can’t get it work, please send the pdf document to me and let me test them.

Tanks for your fast response. I tried width the new fix and now the fist solution works. For the second solution I have to test, in case of error I will mail to you the PDF.

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

Lorenzo