Free Support Forum - aspose.com

Is the bug of IndexOutOfRangeException in generating pdf coming back in version 1.7.3.0?

I’m having the error when it comes to save the pdf file:

error [IndexOutOfRangeException: Index was outside the bounds of the array.]
Aspose.Pdf.Document.x.a(n A_0, Int32 A_1, Int32[] A_2, Int32[] A_3, Int32 A_4) +534
Aspose.Pdf.Document.x.b(n A_0) +98
Aspose.Pdf.Document.n.ap() +87
Aspose.Pdf.Xml.i.a(d A_0, Pdf A_1) +216
Aspose.Pdf.Pdf.Save(String fileName, SaveType saveType, HttpResponse response) +131


here’s the sample code:
for(int i=0; i<counter; i++)
{
planID = ProjectSummaries[i].PlanID;
pdf = GeneratePdfReport(pdf);
}
pdf.Save(“testedpdf”, SaveType saveType, HttpResponse response);


GeneratePdfReport() function adds a few new sections to the same pdf, it will only throw error when counter > 19.




Dear forbi,

Thank you for considering Aspose.

Sorry for the inconvenience you have experienced. Would you please send me an example which can reproduce this error?

the sample codes as below:

Main_function()
{
//if counter less than 30, no error.
//if counter >=30, system throw error "IndexOutOfRangeException: Index was outside the bounds of the array"

int counter = 30;
Pdf pdf;
for(int i=0; i<counter; i++)
pdf = GenerateTestedReport(pdf);

pdf.Save(PdfFileName,SaveType.OpenInBrowser,Response); //view the pdf report in browser
Response.End();
}



private static Pdf GenerateTestedReport(Pdf pdf)
{
for(int x=0; x<12; x++)
{
Aspose.Pdf.Section section = pdf.Sections.Add();

//Add header
HeaderFooter hf1 = new HeaderFooter(section);
section.OddHeader = section.EvenHeader = hf1;
hf1.Margin.Left = 15;
hf1.Margin.Top = 10;

Text hftext = new Text(hf1);
hf1.Paragraphs.Add(hftext);
Segment hrsegment = new Segment(hftext);
hftext.Segments.Add(hrsegment);
hrsegment.Content = “Testing Report”;
hrsegment.TextInfo.FontName = “Arial”;
hrsegment.TextInfo.FontSize = 8;

//add footer
HeaderFooter hf2 = new HeaderFooter(section);
section.OddFooter = section.EvenFooter = hf2;
hf2.Margin.Left = 15;
hf2.Margin.Top = 10;

string printingDate = "Section " + x.ToString();

Text pagetext1 = new Text(hf2);
hf2.Paragraphs.Add(pagetext1);
Segment ftsegment1 = new Segment(pagetext1);
pagetext1.Segments.Add(ftsegment1);
ftsegment1.Content = printingDate;
ftsegment1.TextInfo.Alignment = AlignmentType.Center;

Aspose.Pdf.Table SummaryInfoTable = new Table();

SummaryInfoTable.Margin.Top = 0;
SummaryInfoTable.Margin.Left = 0;

for(int i=0; i<100; i++)
{
Aspose.Pdf.Row newrow = new Row(SummaryInfoTable);
newrow.Cells.Add();
newrow.Cells.Add();
newrow.Cells.Add();
newrow.Cells.Add();
SummaryInfoTable.Rows.Add(newrow);

Aspose.Pdf.Cell HdrCell = SummaryInfoTable.Rows[i].Cells[0];
HdrCell.Border = new BorderInfo((int)BorderSide.All,0.5F);

Aspose.Pdf.Cell DataCell1 = SummaryInfoTable.Rows[i].Cells[1];
DataCell1.Border = new BorderInfo((int)BorderSide.All,0.5F);

Aspose.Pdf.Cell DataCell2 = SummaryInfoTable.Rows[i].Cells[2];
DataCell2.Border = new BorderInfo((int)BorderSide.All,0.5F);

Aspose.Pdf.Cell DataCell3 = SummaryInfoTable.Rows[i].Cells[3];
DataCell3.Border = new BorderInfo((int)BorderSide.All,0.5F);

Aspose.Pdf.Text HdrCellText = new Text("Row Header "+i.ToString());
Aspose.Pdf.Text DataCellText1 = new Text("Row A Data "+i.ToString());
Aspose.Pdf.Text DataCellText2 = new Text("Row B Data "+i.ToString());
Aspose.Pdf.Text DataCellText3 = new Text("Row C Data "+i.ToString());

HdrCell.Paragraphs.Add(HdrCellText);
DataCell1.Paragraphs.Add(DataCellText1);
DataCell2.Paragraphs.Add(DataCellText2);
DataCell3.Paragraphs.Add(DataCellText3);
}

section.Paragraphs.Add(SummaryInfoTable);
}
return pdf;
}

Dear forbi,

Thank you for considering Aspose.

I have got this error. It occurs because there are too many pages in the document. I will fix this bug soon.

Dear forbi,

Thank you for considering Aspose.

I have fixed this bug. Please download hot fix here.

Hi,

I am still getting the IndexOutOfReangeException with the HotFix.
Can you do something about this real soon.

Dear cheeann,

Thank you for considering Aspose.

Have you replaced the dll correctly and rebuilt your solution? I have not found any error when testing the code. If it still won’t work, please send an example which can reproduce the error to me.

I am quite sure the dll was replace and I have check the bin folder.
I don’t think I am doing anything unsually from the sample generate pdf on this forum.

I am able to print the records up to a certain limit but byond that it just give me index out of range.

I am also verify the data are good.

Please advice. This is quite urgent since I need to get my site launch in 2 days time.

Dear cheeann,

Thank you for considering Aspose.

I have fixed this bug. Please download hot fix again.