open and add some text to doc1-5.doc
then loup through a collection of data from a database and add as many docFicheFAS.doc as required. Then Add docAnnexe.doc and finally save as myFinalDoc.doc
It must have been fixed in one of the recent releases as it works perfect for me in Aspose.Word 2.1.14.
Here is my code:
[Test]
public void TestMartinBittner()
{
Document doc1 = TestUtil.Open(@"Other\MartinBittner\doc1-5.doc");
Document doc2 = TestUtil.Open(@"Other\MartinBittner\docFAS.doc");
Document doc3 = TestUtil.Open(@"Other\MartinBittner\docAnnexes.doc");
AppendDoc(doc1, doc2);
AppendDoc(doc1, doc3);
TestUtil.Save(doc1, @"Other\MartinBittner\out.doc");
}
///
/// Moves all sections from one document to another.
///
private void AppendDoc(Document dstDoc, Document srcDoc)
{
while (srcDoc.Sections.Count > 0)
{
Section section = srcDoc.Sections[0];
//The section must first be removed before it can be inserted into a document.
srcDoc.Sections.RemoveAt(0);
dstDoc.Sections.Add(section);
}
}
That was saving in DOC, but I’ve just checked saving in PDF also works well. Make sure you have latest hotfix of Aspose.Pdf too.
///
/// Pass an open document and a short .doc filename. It will use this name to derive the names
/// for the Aspose.Pdf.Xml and PDF files it will create.
///
protected XmlDocument CreatePdfDoc(Document doc, string fileName)
{
string xmlFileName = System.IO.Path.Combine(
TestPath,
System.IO.Path.GetFileNameWithoutExtension(fileName) + " Out" + ".xml");
doc.Save(xmlFileName, SaveFormat.FormatAsposePdf);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFileName);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(xmlDoc, null);
pdf.IsImagesInXmlDeleteNeeded = true;
string pdfFileName = System.IO.Path.Combine(
TestPath,
System.IO.Path.GetFileNameWithoutExtension(fileName) + " Out" + ".pdf");
pdf.Save(pdfFileName);
return xmlDoc;
}
I still have the same error. Here is part of my code:
// Add the docIntro to Final Doc
AppendDoc(docFinal, docIntro);
// Add the FAS to the Final.doc
for (int i = 0; i < totalFiche; i++)
AppendDoc(docFinal, docFicheFAS);
// Add the FAM to the Final.doc
for (int i = 0; i < totalFicheFAM; i++)
AppendDoc(docFinal, docFicheFAM);
// Add the annexes
AppendDoc(docFinal, docAnnexes);
// The following save is commented, but works perfectly. I will send you the
// ProgrammePrevention.doc file to <word@aspose.com> for you to check it out
// docFinal.Save("ProgrammePrevention.doc", Aspose.Word.SaveFormat.FormatDocument, Aspose.Word.SaveType.OpenInBrowser, this.Response);
// Create the Pdf Document from the Document
CreatePdfDoc(docFinal, "TheDoc");
Here is the CreatePdfDoc function I use (I used yours)
protected void CreatePdfDoc(Aspose.Word.Document doc, string fileName)
{
string TestPath = @"c:\test";
string xmlFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".xml");
***// The following line produce the error describe above
doc.Save(xmlFileName, Aspose.Word.SaveFormat.FormatAsposePdf); ***
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFileName);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(xmlDoc, null);
pdf.IsImagesInXmlDeleteNeeded = true;
string pdfFileName = System.IO.Path.Combine(TestPath, System.IO.Path.GetFileNameWithoutExtension(fileName) + ".pdf");
pdf.Save(pdfFileName);
}
I can save the document you’ve sent to me to PDF just fine. Make sure you really have the latest version of Aspose.Word.dll by right clicking on it and checking version. Sometimes a company (your company) firewall or proxy server could cache it and prevent you from obtaining the updated version. I will email you the document I’ve produced.
Please note that you’ve specified explicit row height in the tables and ASpose.Pdf does not support this so some of your rows become narrower.