Hi There,
We’ve been trying to upgrade from v6.5 to a later version due to having issues whereby v6.5 appear to render some text with intermittent spaces and uses the incorrect font/s when rendering.
However having tried v8.1, 8.2.2 and v9.1 (.net2.0 non-authenticode signed) assemblies, these appear to exhibit an error when determining the page count (accesing the Aspose.Words.Document PageCount property), an exception is thrown. We need to use this property as it is needed when using an overload of Aspose.Words.Document.SafeToPdf() where we can specify the ‘PdfOptions’. Additionally, when we used the overloads not requiring the ‘PageCount’ value, the same or similar errors were produced.
I’ve attached a sample solution containing four console projects. Each console projects uses a different version of Aspose.Words (v6.5, 8.1, 8.2.2 and 9.1). All sample projects use the same code (loads a sample document filestream and then tries to access page count).
For the v6.5 project the output is:
================ Using Aspose Document from …
Aspose.Words.Document, Aspose.Words, Version=6.5.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
Getting PageCount …
Page count is 2
Success!
Press any key to continue . . .
================
For the v8.1 project the output is
================
Using Aspose Document from …
Aspose.Words.Document, Aspose.Words, Version=8.1.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
Getting PageCount …
Exception caught …
Message: Need to specify story master when inserting into story other than main text.
Parameter name: position
StackTrace: at ?.?.?(? ?)
at ?.?.?(Document ?, ? ?)
at Aspose.Words.Document.UpdatePageLayout()
at Aspose.Words.Document.get_?()
at Aspose.Words.Document.get_PageCount()
at AsposePageCount.Program.Main(String[] args) in C: \Documents and Settings\ hein\ My Documents\ Visual Studio 2008\ Proj
ects\ AsposePageCount\ AsposePageCount\ Program.cs: line 19
Press any key to continue . . .
================
For the v8.2.2 project the output is
================ Using Aspose Document from …
Aspose.Words.Document, Aspose.Words, Version=8.2.2.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
Getting PageCount …
Exception caught …
Message: Value cannot be null.
Parameter name: position
StackTrace: at ?.?.?(? ?)
at ?.?.?(? ?, ? ?)
at ?.?.?(Document ?, ? ?)
at Aspose.Words.Document.UpdatePageLayout()
at Aspose.Words.Document.get_?()
at Aspose.Words.Document.get_PageCount()
at AsposePageCount.Program.Main(String[] args) in C: \Documents and Settings\ hein\ My Documents\ Visual Studio 2008\ Proj
ects\ AsposePageCount\ AsposePageCount\ Program.cs: line 19
Press any key to continue . . .
================
For the v9.1 project the output is
================ Using Aspose Document from …
Aspose.Words.Document, Aspose.Words, Version=9.1.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56
Getting PageCount …
Exception caught …
Message: Value cannot be null.
Parameter name: position
StackTrace: at ?.?.?(? ?)
at ?.?.?(? ?, ? ?)
at ?.?.?(Document ?, ? ?)
at Aspose.Words.Document.UpdatePageLayout()
at Aspose.Words.Document.get_?()
at Aspose.Words.Document.get_PageCount()
at AsposePageCount.Program.Main(String[] args) in C: \Documents and Settings\ hein\ My Documents\ Visual Studio 2008\ Proj
ects\ AsposePageCount\ AsposePageCount\ Program.cs: line 19
Press any key to continue . . .
================
Here’s a code snippet. The sample.docx is included in the solution zip file.
class Program
{
static void Main(string[] args)
{
using(FileStream fileStream = File.OpenRead("sample.docx"))
{
try
{
Document document = new Document(fileStream);
Console.WriteLine("Using Aspose Document from ...");
Console.WriteLine(document.GetType().AssemblyQualifiedName);
Console.WriteLine("\nGetting PageCount ...");
Console.WriteLine("Page count is " + document.PageCount);
Console.WriteLine("\nSuccess!");
}
catch (Exception exc)
{
Console.WriteLine("\nException caught ...");
Console.WriteLine("\nMessage: " + exc.Message);
Console.WriteLine("\nStackTrace: " + exc.StackTrace);
}
}
}
}