PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Specified argument was out of the range of valid values?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
choreson



Joined: 17 Jul 2007
Posts: 12

PostPosted: Thu Jul 19, 2007 3:15 pm    Post subject: Specified argument was out of the range of valid values? Reply with quote

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
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Thu Jul 19, 2007 4:02 pm    Post subject: Reply with quote

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.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
choreson



Joined: 17 Jul 2007
Posts: 12

PostPosted: Thu Jul 19, 2007 4:16 pm    Post subject: Reply with quote

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);
}
Back to top
View user's profile Send private message
choreson



Joined: 17 Jul 2007
Posts: 12

PostPosted: Thu Jul 19, 2007 4:18 pm    Post subject: Reply with quote

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/852770846_d9f9542dc0_o.png

Yes, I think MergeRight is similar to colspan, that's what I thought.
Back to top
View user's profile Send private message
choreson



Joined: 17 Jul 2007
Posts: 12

PostPosted: Thu Jul 19, 2007 4:27 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com