Free Support Forum - aspose.com

Abnormal behaviour while generating report

Hi,

I am facing an abnormal problem while generating report using Aspose.PDF 4.1.1. I get error message as Invalid index in Rows indexer: 0 when i try to save the pdf as

objPDF.Save("Profile.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)

Stack trace :-

at Aspose.Pdf.Rows.get_Item(Int32 index)
at Aspose.Pdf.Xml.¿.¿(Pdf ¿, Section ¿, Table ¿, Single ¿)
at Aspose.Pdf.Xml.¿.¿(Pdf ¿, Section ¿, HeaderFooter ¿, Table ¿, ¿ ¿, ¿ ¿, ¿ ¿, Boolean ¿)
at Aspose.Pdf.Xml.¿.¿(Pdf ¿, Section ¿, HeaderFooter ¿, Table ¿, ¿ ¿, ¿ ¿, Boolean ¿)
at Aspose.Pdf.Xml.¿.¿(Pdf ¿, Section ¿, ¿ ¿)
at Aspose.Pdf.Xml.¿.¿(Pdf ¿)
at Aspose.Pdf.Xml.¿.¿(¿ ¿, Pdf ¿)
at Aspose.Pdf.Pdf.Save(String fileName, SaveType saveType, HttpResponse response)
at UI_WFRM_PersonnelProf_Frame.GenerateReport()

Code that i used :-

Private Sub GenerateReport()

Try

Dim license As License = New License()

license.SetLicense(Server.MapPath("~/bin/Aspose.Pdf.lic.xml"))

Dim objPDF As Pdf = New Pdf()

Dim section As Section = objPDF.Sections.Add()

'section.TextInfo.FontName = "Arial"

section.TextInfo.FontName = "Times New Roman"

section.TextInfo.FontSize = 10

Dim Margin As MarginInfo = New MarginInfo()

Margin.Left = 20

Margin.Right = 10

Margin.Top = 20

Margin.Bottom = 20

section.PageInfo.Margin = Margin

'objects of tables

Dim objEmployee_Data As EmployeeDataEntity = New EmployeeDataEntity(Me.TargetCHDSUser.EmployeeDataID)

Dim objPersonnel As ChdsPersonnelEntity = New ChdsPersonnelEntity(Me.TargetCHDSUser.PersonnelId)

Dim objPosition As PositionDEntity = New PositionDEntity(objEmployee_Data.CurrentPositionId)

'start title/header section

Dim header As HeaderFooter = New HeaderFooter(section)

section.EvenHeader = header

section.OddHeader = header

Dim headerFooterMargin As MarginInfo = New MarginInfo()

headerFooterMargin.Bottom = 10

headerFooterMargin.Top = 10

header.Margin = headerFooterMargin

Dim tableTitle As Table = New Table()

tableTitle.ColumnWidths = "30% 40% 30%"

tableTitle.DefaultCellTextInfo.FontName = "Arial"

'tableTitle.DefaultCellTextInfo.Alignment = AlignmentType.Center

tableTitle.VerticalAlignment = VerticalAlignmentType.Center

Dim headRow1 As Row = tableTitle.Rows.Add()

headRow1.DefaultCellTextInfo.FontName = "Arial"

headRow1.DefaultCellTextInfo.FontSize = 14

headRow1.DefaultCellTextInfo.IsTrueTypeFontBold = True

headRow1.Cells.Add("PERSONAL PROFILE").DefaultCellTextInfo.FontName = "Arial"

headRow1.Cells.Add("")

headRow1.Cells.Add(objEmployee_Data.CurrentLocation).DefaultCellTextInfo.Alignment = AlignmentType.Right

Dim headRow2 As Row = tableTitle.Rows.Add()

headRow2.DefaultCellTextInfo.FontName = "Arial"

headRow2.DefaultCellTextInfo.FontSize = 14

headRow2.DefaultCellTextInfo.IsTrueTypeFontBold = True

headRow2.DefaultCellTextInfo.Alignment = AlignmentType.Center

headRow2.Cells.Add("")

headRow2.Cells.Add(objPersonnel.LegalName + " (" + objPersonnel.Cai + ")").DefaultCellTextInfo.IsUnderline = True

headRow2.Cells.Add("")

header.Paragraphs.Add(tableTitle)

'end of header

'start of footer

Dim cellPadingHeader As MarginInfo = New MarginInfo()

cellPadingHeader.Left = 4

cellPadingHeader.Right = 2

cellPadingHeader.Top = 5

Dim footer As HeaderFooter = New HeaderFooter(section)

section.EvenFooter = footer

section.OddFooter = footer

footer.Margin = headerFooterMargin

Dim footertable As Table = New Table()

footertable.ColumnWidths = "25% 50% 25%"

footertable.VerticalAlignment = VerticalAlignmentType.Bottom

Dim footerRow0 As Row = footertable.Rows.Add()

footerRow0.Cells.Add("").ColumnsSpan = 3

Dim footerRow1 As Row = footertable.Rows.Add()

footerRow1.DefaultCellTextInfo = colTextInfo

footerRow1.Cells.Add("receives data from a number of sources. See the FAQ’s for the complete list.").ColumnsSpan = 3

Dim footerRow2 As Row = footertable.Rows.Add()

footerRow2.DefaultCellTextInfo.FontName = "Arial"

Dim celfooter1 As Cell = footerRow2.Cells.Add("Printed on " + Date.Now.Date + " at " + Date.Now.Hour.ToString() + ":" + Date.Now.Minute.ToString() + ":" + Date.Now.Second.ToString())

celfooter1.DefaultCellTextInfo.FontSize = 7

celfooter1.Padding = cellPadingHeader

celfooter1.Alignment = AlignmentType.Left

Dim celConf As Cell = footerRow2.Cells.Add("CONFIDENTIAL RESTRICTED ACCESS")

celConf.DefaultCellTextInfo.FontSize = 10

celConf.DefaultCellTextInfo.IsTrueTypeFontBold = True

celConf.Alignment = AlignmentType.Center

celConf.Padding = cellPadingHeader

Dim celpage As Cell = footerRow2.Cells.Add("Page $p of $P ")

celpage.DefaultCellTextInfo.FontSize = 7

celpage.Alignment = AlignmentType.Right

celpage.Padding = cellPadingHeader

footerRow2.DefaultCellTextInfo.Alignment = AlignmentType.Center

footer.Paragraphs.Add(footertable)

'end of footer

'save the file to response

objPDF.Save("Profile.pdf", Aspose.Pdf.SaveType.OpenInAcrobat, Response)

I observe that when i comment out the lines highlighted in red from header and footer section alternatively the report runs fine.

Is the content of header or footer exceeding the section alloted for header or footer. If this is the reason then why isn't this behaviour consistance? Request you to kindly help me understand this.

Thanks a lot in advance.

Regards,

Abhijit Jaiswal

Hello Abhijit,

Thanks for using our products.

I have tested the scenario using Aspose.Pdf for .NET 4.4.0 and I am unable to notice the problem. The PDF document is being generated without any problem. I have used the same code snippet as shared in your earlier post. For your reference, I have also attached the resultant PDF that I have generated. Please take a look.

Please try using Aspose.Pdf for .NET 4.4.0 and in case you face any problem or you have any further query, please feel free to contact. You can download Aspose.Pdf for .NET 4.4.0 from here.

We apologize for your inconvenience.