PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 6:27 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jul 19, 2007 3:15 pm 
Offline

Joined: Tue Jul 17, 2007 7:12 pm
Posts: 12
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jul 19, 2007 4:02 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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


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

Joined: Tue Jul 17, 2007 7:12 pm
Posts: 12
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);
}


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

Joined: Tue Jul 17, 2007 7:12 pm
Posts: 12
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.


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

Joined: Tue Jul 17, 2007 7:12 pm
Posts: 12
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 147 guests


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 post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group