IndexOutOfRangeException on Document.SavetoPdf() call

Hey there, I’ve just made up a quick ‘n’ nasty doc-to-pdf app to try out aspose.words before possibly integrating in a large project and I’ve run into a problem. When trying to convert the attached document using Document.SaveToPdf() the app throws an IndexOutOfRangeException:

private void button1_Click(object sender, EventArgs e)
{
    if (selectFileControl1.Filename != "" && selectFileControl2.Filename != "")
    {
        String FileToOpen = selectFileControl1.Filename;
        String FileToSaveAs = selectFileControl2.Filename;

        Document WordFile = new Document(FileToOpen);
        WordFile.SaveToPdf(FileToSaveAs); //IndexOutOfRangeException
    }
    else
    {
        MessageBox.Show("You must select a valid filename for both the source and destination files");
    }
}

Any ideas?

Hi
Thanks for your request. I can’t reproduce this problem on my side. I successfully converted your document to PDF. Maybe you attached wrong document.
If it is possible, please create a sample application that will demonstrate the problem.
Best regards.

Sure thing, attached is the test app I’m working with. I double checked and I definitely attached the same document I’m having problems with. I’ve noticed it does actually start to produce a PDF file but it’s faulty, I’ve attached the PDF file the original .doc file attachment generates. I did some extra testing on the side and dumbed my code down even more by hardcoding the paths in and got the same error:

String FileToOpen = @"C:\document.doc";
String FileToSaveAs = @"C:\document.pdf";
Document doc = new Document (FileToOpen);
doc.SaveAsPdf(FileToSaveAs); //IndexOutOfRangeException

Thanks for your help.

I am having the same problem, but I noticed that a simple document with only a few lines of text worked fine. So, in an effort to determine the cause of the problem I started removing paragraphs from my document until it finally saved as a pdf. I discovered that I get this error when my document contains bullets, but only the bullets that are round and solid black. If I change the bullets to the open circle or any other bullet type no problems. More recently I discovered that the degrees symbol (the open round superscript circle) also causes the exception. I posted a question on this forum a couple weeks back, but the support staff could not duplicate my error. I hope this helps and there is a way we can get this issue resolved.

Matt

Hey thanks for that MattA - I can confirm that I can convert the doc file without problems after removing the bullet points or changing them from solid to hollow dots. Bizarre! The PDF file looks fantastic too, apart from a table in one of the footers it’s a perfect replica of the .doc file. I’ll look into it further and see if I can discover a work around for the issue.

Hi
Thank you for additional information. But unfortunately I am still unable to reproduce this problem on my side.
I also tried to create simple document with bullets (as you mentioned) and still no errors. I attached document I created and output PDF. Could you please try to convert this document to PDF and let me know if it causes the problem on your side?
Maybe there is some specific in my environment so I can’t reproduce the problem.
Best regards.

I tried the file you attached and it still would not produce a pdf. So, I did a little more testing and discovered that anytime the bullet is created from the “symbol” font is when I have problems. I then created a blank document and went to Insert > Symbol and picked a random symbol. The font at the top of the dialog box was set to symbol. This caused the same error. I then repeated this process several times, each time picking a different (random) symbol and each time I received the error. So, I then created a new document set the font to symbol and typed a character. This too produced an error. So, I am confident that the cause of the problem is the symbol font.

Matt

Hi
Thank you for additional information. I still can’t reproduce the problem on my side. I will try to install clear Windows on Virtual Machine and test your document there. Maybe there are some fonts installed in my system so I can’t reproduce the problem. I will do more testing and let you know how it goes.
Best regards,

Hi

I installed clear copy of WinXP on VMWare and still can’t reproduce the problem. Could you please provide me information about your environment? Maybe this information could help me to recreate the problem.
Best regards.

Alexey,

I’de be happy to provide whatever you need. But, can you be a little more specific as to what I need to provide? Thanks for your interest and diligence in solving this issue.

Matt

Everything Matt has said applies to me too - creating a new document, changing the font to Symbol, hitting the ‘a’ character on my keyboard and saving that document caused my test program to crash when trying to convert it. I also tried creating a new document, changing the font to Symbol, didn’t type anything and saved the blank document but that did not cause the test app to crash.

Here is some info on my system (also see attached files from running msinfo32 and dxdiag). If there’s anything else you’d like to know please let me know.

  • Running evaluation version of Aspose Words 6.0.0.0 (Right clicking on C:\Program Files\Aspose\Aspose.Words\Bin\net2.0\Aspose.Words.dll, clicking “Version” tab and selecting “Product Version” reports version no. 2008.11.28)
  • Control Panel > System reports this:
    • Del Vostro VOSTRO_200 Intel® Core™2 CPU 4400 @ 2.00Ghz. 1.20 GHz, 2.00 GB of RAM
  • 241 GB free on hard disk
  • Typing “winver” into Start>Run reports this:
    • Windows XP Professional SP2, ver 5.1 (Build 2600.xpsp_sp2_qfe.080814-1242 : Service Pack 2)
  • Currently running IE 7 (ver 7.0.5730.11), though was previously running IE 8 beta (ver 8.0.6001.17184)
  • Typing “BLOCKED SCRIPTalert(navigator.userAgent)” in the IE address bar reports this:
    • Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022
  • Test app running in Visual Studio 2008 (ver 9.0.30729.1 SP)
  • Also have VS 2005 installed (ver 8.0.50727.762 (SP .050727-7600))
  • Project targets .NET framework 3.5 (though also crashes while targeting ver 2.0)
  • Info on my C:\windows\fonts\symbol.ttf file
    • Size: 67.8 KB (69,464 bytes)
    • Modified: Wednesday, 4 August 2004, 7:00:00 AM
  • Info on my C:\windows\fonts\symbole.fon file
    • Size: 55.0 KB (56,336 bytes)
    • Modified: Wednesday, 4 August 2004, 7:00:00 AM
  • Also tested with a colleague’s symbol.ttf & symbole.fon files:
    • Symbol.ttf:
      • Size: 67.8 KB (69,464 bytes)
      • Modified: Monday, 31 March 2003, 10:00:00 PM
    • Symbole.fon
      • Size: 55.0 KB (56,336 bytes)
      • Modified: Monday, 31 March 2003, 10:00:00 PM
  • Running Office 2003 (Outlook, Access, Excel, InfoPath, Powerpoint, Publisher, Word (ver 11.8237.8221 SP3))
  • Running Visual Basic 6.0 (SP6)
    Version 9782
    VBA: 6.09782
    Forms3: 12.0.6307.500
  • Direct X version 9.0c (4.09.0000.0904) installed
  • Adobe reader 8.1.3 installed

Hi
Thank you for additional information. I understand that this sounds strange but I still can’t reproduce your problem. I tried converting your document on different environments and no error occurs. Also I tried to create simple document with Symbol font as you described in your previous post and still no errors.
I found only one issue with Symbol font. When insert Symbol text programmatically text is not displayed properly in output PDF.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Symbol";
builder.Write("a b c d e f g");
doc.Save(@"Test048\out.doc");
doc.SaveToPdf(@"Test048\out.pdf");

I logged this issue in our defect database as issue #6971.
I have no idea why IndexOutOfRangeException occurs on your side. Currently I can only suggest you wait for the next release that will be published tomorrow. Maybe some of changes will fix your problem.
Best regards.

Very odd! I’ll wait until the new version comes out and give that a go. I tried building the test project I’m using and running it to see what would happen, not surprisingly it’s still crashing but I was able to get a stack trace. Most of the type & parameter names are obfuscated so I don’t know how useful it’ll be, but you never know:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at 㵏.㺥.㺫(㺟 㺬)
at 㵏.㸠.㹁()
at 㵏.㸠.ޙ(Stream Ԏ)
at 㵏.㸠.ޙ(String Ԍ)
at 㵏.㸠.㸷(String 㵊)
at 㵏.㸠.㸳(String 㵊, FontStyle ॳ, Boolean 㸴)
at 㵏.㸠.ਲ(String 㵊, FontStyle ॳ, Boolean 㸴)
at 㳁.㴼…ctor(㳱 context, String familyName, FontStyle requestedStyle)
at 㳁.㶏…ctor(㳱 context, String familyName, FontStyle requestedStyle)
at 㳁.㴼.㵉(㳱 ಾ, String 㵊, FontStyle 㵋, Boolean 㵌)
at 㳁.㶀.ਲ(String 㵊, FontStyle ॳ, Boolean 㵌)
at 㳁.㿏.㿘(૩ ୸)
at 㳁.㾶.⊌(૩ ୸)
at 㳁.㿤.VisitGlyphs(૩ glyphs)
at ઺.૩.Accept(ૃ visitor)
at ઺.ઽ.Accept(ૃ visitor)
at ઺.ૄ.Accept(ૃ visitor)
at ઺.ઽ.Accept(ૃ visitor)
at ઺.ૄ.Accept(ૃ visitor)
at ઺.ઽ.Accept(ૃ visitor)
at ઺.ૄ.Accept(ૃ visitor)
at ઺.ઽ.Accept(ૃ visitor)
at ઺.હ.Accept(ૃ visitor)
at Aspose.Words.Document.SaveToPdf(Int32 pageIndex, Int32 pageCount, Stream stream, PdfOptions options)
at Aspose.Words.Document.SaveToPdf(Int32 pageIndex, Int32 pageCount, String fileName, PdfOptions options)
at Aspose.Words.Document.SaveToPdf(String fileName)
at Aspose_test.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\adam.mcdonnell\My Documents\Visual Studio 2008\Projects\Aspose test\Aspose test\Form1.cs:line 47
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Hi Matt and Adam,
We have released new version of Aspose.Words. You can download it from here:
https://releases.aspose.com/words/net
Best regards.

Alexey,

I tried the new version, the issue is not resolved. I still get the IndexOutOfRangeException.

Thanks

Thanks Matt,
I will consult with our developers ant provide you more information. (I still can’t reproduce the problem)
Best regards.

Hi,
Today I downloaded and tried the new method Document.SaveToPdf(), but I have the samen problems:
Server Error in ‘/’ Application.
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

Line 223: + Path.ChangeExtension(Path.GetFileName(theFilePath), theExtension);
Line 224:
Line 225: theDoc.SaveToPdf(theFilePath);
Line 226:
Line 227: MemoryStream theMemoryStream = new MemoryStream();

Source File: …\Library\Vcl\DocumentGeneration\AsposeDocumentGenerator.cs Line: 225

Stack Trace:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
ប.⍷.⎕() +383
ប.⍷.᳒() +341
ប.Ӣ.Ც(Document ඔ, ӣ ᩥ) +273
Aspose.Words.Document.UpdatePageLayout() +43
Aspose.Words.Document.get_Ӣ() +38
Aspose.Words.Document.get_PageCount() +31
Aspose.Words.Document.SaveToPdf(String fileName) +59
Vermaase.Vcl.DocumentGeneration.AsposeDocumentGenerator.SaveDocument(CombinedDocumentHolder documentHolder, HttpResponse response, Boolean openInBrowser, Stream stream) in D:\CVS_WORK…\Vcl\DocumentGeneration\AsposeDocumentGenerator.cs:225
Vermaase.Vcl.DocumentGeneration.AsposeDocumentGenerator.GenerateDocument(DocumentInfo docInfo, CombinedDocumentHolder combinedDocumentHolder, HttpResponse response, Boolean openInBrowser, Stream stream) in D:\CVS_WORK…\DocumentGeneration\AsposeDocumentGenerator.cs:136
Vermaase.Vcl.DocumentGeneration.AsposeDocumentGenerator.GenerateDocument(DocumentInfo docInfo, CombinedDocumentHolder combinedDocumentHolder, HttpResponse response, Boolean openInBrowser) in D:\CVS_WORK…\Vcl\DocumentGeneration\AsposeDocumentGenerator.cs:60
Vermaase.Allianz.AOS.WebControls.AllianzDocumentenHandler.ProcessRequest(HttpContext context) in D:\CVS_WORK…\AllianzDocumentenHandler.cs:58
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
Kind regards,
Marcel vd Wel

Hello Marcel!
Thank you for your request.
As I can see from the stack trace you get this exception in different place of the code. Please attach your document reproducing the problem. We’ll try on our side.
Regards,

Hi,
The problem as descibed above is also the problem I am experiencing, althoiugh I do not use bullets in my document. A few days ago I downloaded the latest version of Aspose.Words (6.1).
What I do is very simple. I created a document in Microsoft Word 2007. I saved the Word Document as MS Word 2003 document (.doc).
I open the document with Aspose Words and make a call to the SaveToPdf method, which gives an IndexOutOfRangeException. I tried to save it with the default settings, to a memorystream, etc. but all give the same error.
Details of the error below:
-----------------------------------------

System.IndexOutOfRangeException was unhandled by user code
Message="De index ligt buiten de matrixgrenzen."
Source="Aspose.Words"
StackTrace:
bij ប.⍷.⎕()
bij ប.⍷.᳒()
bij ប.Ӣ.Ც(Document ඔ, ӣ ᩥ)
bij Aspose.Words.Document.UpdatePageLayout()
bij Aspose.Words.Document.get_Ӣ()
bij Aspose.Words.Document.get_PageCount()
bij Aspose.Words.Document.SaveToPdf(String fileName)
bij System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
bij System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
bij System.Web.UI.Control.OnLoad(EventArgs e)
bij System.Web.UI.Control.LoadRecursive()
bij System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

----------------------------------
I noticed that the document.PageCount property also gives the same index out of range error. It looks like the pagecount property does not work properly.
Kind regards,
Jochem

Hi
Thank for your request. Could you please attach your document for testing? I will try to reproduce the problem on my side and provide you more information.
Best regards.