Hi,
I'm trying to generate pdf documents from docx templates. I filled this docx templates with xml data and then convert generated docx document to pdf. I use mail merge to generate.
When I'm trying to convert to pdf the generated word document with Tables (by the way, as you'll see I use ExecuteGroup method to fill table with data), I got ArgumentOutOfRangeException (Length cannot be less than zero).
On the other hand, when I generate document 'without' table and use Execute mailmerge method, I'm able to successfully convert generated document to pdf with ConvertToPDF() method.
I attached docx template, the xml data and the code I use for generate document. Am I doing something wrong?
Code:
DocToPDFConverter docToPdfConverter = new DocToPDFConverter();
WordDocument document = new WordDocument();
document.Open(templateFilePath + "TemplateWithTable.docx");
document.MailMerge.MergeImageField += MailMergeOnMergeImageField;
XDocument xmlDoc = null;
using (StreamReader oReader = new StreamReader(templateFilePath + "XMLData.xml", Encoding.GetEncoding("ISO-8859-9")))
{
xmlDoc = XDocument.Load(oReader);
}
//data get from db as xml file
DataSet ds = new DataSet();
ds.ReadXml(xmlDoc.CreateReader());
DataTableCollection childTables = ds.Tables;
foreach (DataTable childTable in childTables)
{
if(childTable.TableName != "root")
{
document.MailMerge.ExecuteGroup(childTable);
}
}
document.MailMerge.Execute(childTables["root"]);
document.Save(templateFilePath + "GeneratedDocument.doc");
//I get the exception on this line!
PdfDocument pdfDocument = docToPdfConverter.ConvertToPDF(templateFilePath + "GeneratedDocument.doc");
pdfDocument.Save(templateFilePath + "GeneratedDocument.pdf");
Thanks for your help.
Caglar
Attachment:
Documents_29274860.zip