Come across an issue in Aspose.Words, where it throws a System.ArgumentOutOfRangeException: Index and count must refer to a location within the string.
error converting Docx to Pdf. I have a standalone Console app which works fine with the old version (19.2) and new version (24.6) of the Aspose.Words DLL.
But when running through the integration test in codebase (tried locally, and deployed) throws an Error and does not convert.
Detail:
27/08/2024 1:51:55 PM [00040] Err: System.ArgumentOutOfRangeException: Index and count must refer to a location within the string.
Parameter name: count
at System.String.Remove(Int32 startIndex, Int32 count)
at .(String , String )
at .(String , String )
at .( )
at Aspose.Words.Fields.FieldIf.86q6acmbfp2kjwdcs2q6rs3uwmqt2zc9 ( )
@andrew.roberts Could you please attach your problematic input document here for testing? We will check the issue and provide you more information.
@andrew.roberts Thank you for additional information. Unfortunately, I cannot reproduce the problem using the latest 24.8 version of Aspose.Words and the following simple code:
Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.pdf");
out.pdf (38.9 KB)
I have found the issue. It cannot handle certain dotx files, so when you call MailMerge.DeleteFields
, the resultant docx is corrupt.
static void Main(string[] args)
{
new AsposeLicenses();
var doc = new Aspose.Words.Document($"{path}Template_Xerox.dotx");
// Perform mail merge (optional)
doc.MailMerge.Execute(fieldNames, fieldValues);
// Remove "left over" fields
doc.MailMerge.DeleteFields();
// Save document
doc.Save(name, SaveFormat.Docx);
var docx = new Aspose.Words.Document(name);
docx.Save($"{path}AsposeWords_192.pdf", Aspose.Words.SaveFormat.Pdf); //throws error
}
I will try to send you a dotx that still has the issue
@andrew.roberts Also, provide field names and values used to execute mail merge, so we could test your full scenario.