Good afternoon Marcia,
Thank you for your advice, it is really appreciated. However, we are still encountering an issue with the Save to file method. Today we have got a mixture of generic GDI+ errors and null reference exceptions.
Generic GDI+System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+.
at System.Drawing.Graphics.MeasureCharacterRanges(String text, Font font, RectangleF layoutRect, StringFormat stringFormat)
at sprᬊ.ᜀ(String A_0, Font A_1, StringFormat A_2)
at sprᬊ.ᜁ(String A_0, Font A_1, StringFormat A_2)
at sprᬊ.ᜀ(TextRange A_0, TextRange A_1, Paragraph A_2, String A_3)
at sprᬊ.ᜀ(TextRange A_0, String A_1)
at sprស.ᜅ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprហ.ᜂ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprន.ᜀ(sprឋ A_0, sprច A_1, sprᬊ A_2)
at sprᬂ.ᜒ()
at sprᬂ.ᜓ()
at sprᬂ.ᜀ(IDocument A_0)
at sprᬱ.ᜀ(Document A_0, Stream A_1)
at Spire.Doc.Document.ᜄ(String A_0)
at Spire.Doc.Document.SaveToFile(String fileName, FileFormat fileFormat)
Null referenceSystem.NullReferenceException: Object reference not set to an instance of an object.
at spr?.?(String A_0, String A_1, Single A_2, FontStyle A_3)
at spr?.?(String A_0, Single A_1, FontStyle A_2, CharacterFormat A_3)
at spr?.?(TextRange A_0, spr? A_1, RectangleF& A_2, Boolean A_3, spr? A_4)
at spr?.?(TextRange A_0, IDocumentObject A_1, Paragraph A_2, String A_3, Boolean A_4)
at spr?.?(spr? A_0)
at spr?.?(RectangleF A_0)
at spr?.?(spr? A_0)
at spr?.?(RectangleF A_0)
at spr?.?(spr? A_0)
at spr?.?(RectangleF A_0)
at spr?.?(spr? A_0)
at spr?.?(RectangleF A_0)
at spr?.?(spr? A_0, spr? A_1, spr? A_2)
at spr?.?()
at spr?.?()
at spr?.?(IDocument A_0)
at spr?.?(Document A_0, Stream A_1)
at spr?.?(Document A_0, Stream A_1, ToPdfParameterList A_2)
at Spire.Doc.Document.?(String A_0)
at Spire.Doc.Document.SaveToFile(String fileName, FileFormat fileFormat)
The errors are still
intermittent, so to demonstrate our issue we have created a test example that simply loops through, reads a word file, and then converts the XPS.
- Code: Select all
const string path = @"C:\PrintTest\";
const int runs = 100;
/*
* The save code is in a loop as the error is intermittent (occurs sometimes)
*/
for (int runNumber = 1; runNumber <= runs; runNumber++)
{
using (Document doc = new Document($"{path}Merged.docx"))
{
//Error is thrown here
doc.SaveToFile($"{path}Converted.xps", FileFormat.XPS);
//The following line works without issue (saving as Docx)
//doc.SaveToFile($"{path}Converted.docx", FileFormat.Docx);
}
}
In our actual application we will be reading and dealing with multiple files.
I have attached the files, evidence, projects and along with this post. However, I have been unable to upload the main word file as it is too big. Is there another way you can retrieve this?
Thank you and kind regards,
Michael Willis
Login to view the files attached to this post.