We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

System.IndexOutOfRangeException was caught at at Syncfusion.Pdf.Graphics.PdfTextElement..ctor(String text)

Hi ,i am new to syncfusion WinRt,trying to write my content to a pdf using following code:

  RectangleF r0 = new RectangleF(x, y, ((float)page.Graphics.ClientSize.Width - 100), page.Graphics.ClientSize.Height - y);

                PdfTextElement txtElement_r0 = new PdfTextElement(text);
                txtElement_r0.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, font);

                PdfStringFormat f_r0 = new PdfStringFormat();
                f_r0.LineLimit = true;
                f_r0.WordWrap = PdfWordWrapType.Word;
                txtElement_r0.StringFormat = f_r0;


                result_f_r0 = txtElement_r0.Draw(page, r0);

don't know why but at times it gives me an exception while calling Draw method and the exception message is something like this.
"

System.IndexOutOfRangeException was caught

  HResult=-2146233080

  Message=Index was outside the bounds of the array.

  Source=Syncfusion.Pdf.WinRT

  StackTrace:

       at System.Text.Windows1252Encoding.GetBytes(String s)

       at Syncfusion.Pdf.Graphics.PdfStandardFont.Convert(String text)

       at Syncfusion.Pdf.Graphics.PdfTextElement..ctor(String text)

       at _WritingType.ProjectsPage.<PdfDrawElement>d__40.MoveNext() in c:\Users\hinaBasit\Desktop\My changes\windows8apps\WindowsStore\WritingType\_WritingType\Src\ProjectsPage.xaml.cs:line 1348

"
please help me out,its now a headache for me.

Thanks
Hina

4 Replies

GL George Livingston Syncfusion Team December 31, 2012 12:27 PM UTC

Hi Hina,

Thank you for your using Syncfusion products.

We are not able to reproduce the error in our side with the mentioned scenario. Can you please provide us the sample to reproduce the issue, it would be more helpful for us to investigate on this forum.

Please let us know if you have any questions.

Regards,

George



RD Ross Dargan May 1, 2013 04:03 PM UTC

I have been able to re-create this issue (and can suggest a fix).

Microsoft inserts control chars when you use the inbuilt globalisation. For example if you use the following winrt code:-

 Windows.Globalization.DateTimeFormatting.DateTimeFormatter datef =
                    new DateTimeFormatter("longdate");
                string text= datef.Format(TheDate);

And then output text you will see something that looks like this:
text = "‎01‎ ‎May‎ ‎2013"

However if you do a .length on it you will get 16 chars (not 11 as you would expect). Looking at the char array you see the following:-

text.ToCharArray()
{char[16]}
    [0]: 8206 '‎'
    [1]: 48 '0'
    [2]: 49 '1'
    [3]: 8206 '‎'
    [4]: 32 ' '
    [5]: 8206 '‎'
    [6]: 77 'M'
    [7]: 97 'a'
    [8]: 121 'y'
    [9]: 8206 '‎'
    [10]: 32 ' '
    [11]: 8206 '‎'
    [12]: 50 '2'
    [13]: 48 '0'
    [14]: 49 '1'
    [15]: 51 '3'

8206 doesn't print - its used to donate left-to-right printing (http://en.wikipedia.org/wiki/Left-to-right_mark)

The Syncfusion print code uses a 256 char to byte conversion table, but because 8206 is above that we get an index out of range exception. 

You can fix it by changing the GetBytes method in the System.Text.Windows1252Encoding.cs file to this:

public override byte[] GetBytes(string s)
{
    List<byte> list = new List<byte>();
    foreach (char ch in s)
    {
        int index = (int) ch;
        if (index<Windows1252Encoding.m_charCodeTable.Length)
        {
            list.Add((byte) Windows1252Encoding.m_charCodeTable[(int) ch]);
        }
    }
    return list.ToArray();
}

If you are an end user and you want to work around the bug then you can use the following linq to cleanse your string before passing it to the 

text = new string(text.ToCharArray().Where(p => (int) p < 256).ToArray());

This code changes you string to:-

text.ToCharArray()
{char[11]}
    [0]: 48 '0'
    [1]: 49 '1'
    [2]: 32 ' '
    [3]: 77 'M'
    [4]: 97 'a'
    [5]: 121 'y'
    [6]: 32 ' '
    [7]: 50 '2'
    [8]: 48 '0'
    [9]: 49 '1'
    [10]: 51 '3'

Hopefully that should be enough info to help fix the issue

Thanks

Ross


RD Ross Dargan May 1, 2013 04:05 PM UTC

The assembly to fix is Syncfusion.Pdf.WinRT.dll btw.


US Uthistran S Syncfusion Team May 14, 2013 11:38 AM UTC

Hi Ross,

We regret for the inconvenience caused.
Thank you for your update. We have updated the details regarding the mentioned issue in the incident #108268.
Incident Link
Please, let us know if there is any concerns.
Thanks,
Uthistran S.

Loader.
Live Chat Icon For mobile
Up arrow icon