Hi,
I need to generate a preview of a document inside my application and I want to limit the number of pages to generate (sometimes we need to print 3000 pages but we only preview the 20 first pages).
To do the preview, we save the Aspose.Words Document to an XPS Document file.
And to limit the number of pages to preview, we used the property PageSet on XpsSaveOptions.
Document document = new Document(); // 1 page
SaveOptions saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Xps);
int[] pages = Enumerable.Range(0, 20).ToArray(); // [1-20]
((XpsSaveOptions)saveOptions).PageSet = new PageSet(pages);
document.Save(@"C:\output.xps", saveOptions); // ArgumentOutOfRangeException is thrown
And it works great on big documents! But unfortunately, when I save a small document (with 1 page, see code above), it crashes with this exception :
System.ArgumentOutOfRangeException: 'Page index exceeds the index of the last page in the document.
Nom du paramètre : pageIndex'
at ..ctor(Int32[] , Int32 )
at . (Int32 )
at .( , )
at . ( )
at . ( )
at Aspose.Words.Document.( )
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(String fileName, SaveOptions saveOptions)
What am I doing wrong ? Can I achieve this in an other way ?
I saw the property LayoutOptions.Callback on the Document object but, unfortunetly, we already use that Callback for an other purpose (and we need the document to be fully reflowed/rendered).
Edit: Aspose.Words version has been updated from v21.02 to v21.03, but the exception is always there.