PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Specified argument was out of the range of valid values?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=195
Page 1 of 1

Author:  choreson [ Thu Jul 19, 2007 3:15 pm ]
Post subject:  Specified argument was out of the range of valid values?

I am testing MigraDoc by following the Invoice sample application. But this line in my code:

pdfRender.RenderDocument();

gives me the following error message. I don't know why.

Well, I basically did this:

Section section = this.document.AddSection();
this.table = section.AddTable();

And then created 3 columns and 2 rows for the table. Then I set the table edge, and then I try to render the document into PDF!

StackTrace:
at MigraDoc.DocumentObjectModel.Tables.Cells.get_Item(Int32 index) at MigraDoc.DocumentObjectModel.Tables.Table.get_Item(Int32 rwIdx, Int32 clmIdx) at MigraDoc.DocumentObjectModel.Visitors.MergedCellList.GetEffectiveBorders(Cell cell) at MigraDoc.Rendering.TableRenderer.FormatCells() at MigraDoc.Rendering.TableRenderer.InitFormat(Area area, FormatInfo previousFormatInfo) at MigraDoc.Rendering.TableRenderer.Format(Area area, FormatInfo previousFormatInfo) at MigraDoc.Rendering.TopDownFormatter.FormatOnAreas(XGraphics gfx, Boolean topLevel) at MigraDoc.Rendering.FormattedDocument.Format(XGraphics gfx) at MigraDoc.Rendering.DocumentRenderer.PrepareDocument() at MigraDoc.Rendering.PdfDocumentRenderer.PrepareDocumentRenderer(Boolean prepareCompletely) at MigraDoc.Rendering.PdfDocumentRenderer.PrepareRenderPages() at MigraDoc.Rendering.PdfDocumentRenderer.RenderDocument() at PdfSharpToPdf.CreatePDF() in c:\Documents and Settings\antonylau\My Documents\Visual Studio 2005\WebSites\MyWebSites\PdfSharpToPdf.aspx.cs:line 351

Exception Message:
Specified argument was out of the range of valid values. Parameter name: index

Author:  Thomas Hoevel [ Thu Jul 19, 2007 4:02 pm ]
Post subject: 

I suspect you reduced the number of columns without adjusting the MergeRight property of some cells.
Merging with cells that don't exist causes an index out of range exception.
MergeRight is similar to colspan in HTML.

Author:  choreson [ Thu Jul 19, 2007 4:16 pm ]
Post subject: 

Thomas Hövel wrote:
I suspect you reduced the number of columns without adjusting the MergeRight property of some cells.
Merging with cells that don't exist causes an index out of range exception.
MergeRight is similar to colspan in HTML.


OK, thanks. See the source code:

protected void CreatePDF()
{
try
{
document = new Document();
document.Info.Title = "PdfSharpToPdf.aspx.cs";
document.Info.Subject = "Testing MigraDoc PDF Generator";
document.Info.Author = "Antony Lau";

//You should create at least one section for each MigraDoc document.
Section section = document.AddSection();


//Add a table to this section.
table = section.AddTable();
table.Borders.Color = new Color(81, 125, 192);

Column column;

//You must define your columns before you can add a row.
column = table.AddColumn("3cm"); // for first, last names
column = table.AddColumn("3cm"); // for phone and its extension
column = table.AddColumn("3cm"); // for location and room number.

Row row = table.AddRow(); // row 1, the header
row.HeadingFormat = true;
row.Format.Font.Bold = true;
row.Cells[0].AddParagraph("This is the header of the table in Bold");
row.Cells[0].MergeRight = 3;

row = table.AddRow(); // row 2
row.Format.Font.Bold = true;
row.Shading.Color = new Color(211, 211, 211);
row.Cells[1].AddParagraph("Visiting Scholars of Biochemistry".ToUpper());

row.Cells[1].Format.Alignment = ParagraphAlignment.Center;
row.Cells[1].MergeRight = 3;

row = table.AddRow(); // contact info row, row 3
row.Format.Font.Bold = false;
row.Cells[0].AddParagraph("Marietta Johnson");
row.Cells[1].AddParagraph("123-456-7890");
row.Cells[2].AddParagraph("Room 3141, Gregory Hall");

// How do we use SetEdge? For this table, I have 3 columns and 3 rows, so,
// should I do it like below?

table.SetEdge(0, 0, 3, 3, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75);

PdfDocumentRenderer pdfRender = new PdfDocumentRenderer(true);

pdfRender.Document = document;
pdfRender.RenderDocument(); // This line generates error.
pdfRender.Save("c:/phonebook_pdfsharp.pdf");
}
catch (Exception ex)
{
Response.Write("<b>StackTrace: </b><br/>" +ex.StackTrace + "<br/><br/>");
Response.Write("<b>Exception Message:</b><br/>" + ex.Message);
}

Author:  choreson [ Thu Jul 19, 2007 4:18 pm ]
Post subject: 

Thomas Hövel wrote:
I suspect you reduced the number of columns without adjusting the MergeRight property of some cells.
Merging with cells that don't exist causes an index out of range exception.
MergeRight is similar to colspan in HTML.


I want to create one table that looks like so:

http://farm2.static.flickr.com/1186/852 ... 2dc0_o.png

Yes, I think MergeRight is similar to colspan, that's what I thought.

Author:  choreson [ Thu Jul 19, 2007 4:27 pm ]
Post subject: 

Thomas Hövel wrote:
I suspect you reduced the number of columns without adjusting the MergeRight property of some cells.
Merging with cells that don't exist causes an index out of range exception.
MergeRight is similar to colspan in HTML.


Thank you, Thomas, you are very right! I printed the source code of invoice.cs and the PDF it generated and closely studied them.

I found out that the value of MergeRight should be n-1, where n is the number of columns the cell spans. Initially I had MergeRight = n.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/