PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Pdfsharp and tables
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3598
Page 1 of 1

Author:  v_k [ Fri Jun 09, 2017 12:49 pm ]
Post subject:  Pdfsharp and tables

Hello,

I develop a project in C# (.Net 4.5) and I must generate a PDF from users.
I found more projects allows this but PDFsharp is only .NET library compatible with my licence (CC-By-SA 4.0).
However, I have a problem : PDFsharp can create tables ?

Thanks for your answers !

(PS : sorry for english)

Author:  TH-Soft [ Fri Jun 09, 2017 3:49 pm ]
Post subject:  Re: Pdfsharp and tables

Hi!
v_k wrote:
However, I have a problem: PDFsharp can create tables?
A table is text with some lines drawn around it. PDFsharp can draw text and it can draw lines, so it can create tables.

MigraDoc makes creating tables easier:
http://pdfsharp.net/wiki/Invoice-sample.ashx

Author:  v_k [ Fri Jun 09, 2017 7:29 pm ]
Post subject:  Re: Pdfsharp and tables

Oh, it was in "Invoice". Thanks and sorry :-)

Author:  v_k [ Sat Jun 10, 2017 3:37 pm ]
Post subject:  Re: Pdfsharp and tables

Hello,

I has started on MigraDoc but I have error with a function :
Quote:
this.table.SetEdge(0, 0, 6, 2, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
(it in example - l 107)

Quote:
L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection.
Nom du paramètre : index

The index was out of bounds. It must not be negative and must be less than the size of the collection.
Parameter Name: index

Why ?

I wanted begin by generate headers to my table with 7 columns but I don't understand SetEdge() function.
this.table.SetEdge(a, b, c, d, Edge.Box, BorderStyle.Single, 0.75, Color.Empty)
Who is it a, b, c and d ?

Author:  v_k [ Sat Jun 17, 2017 9:27 am ]
Post subject:  Re: Pdfsharp and tables

Nobody ? :(

Author:  TH-Soft [ Sun Jun 18, 2017 8:19 am ]
Post subject:  Re: Pdfsharp and tables

Hi!
v_k wrote:
Who is it a, b, c and d ?
Columns and rows.
Make sure your table has enough rows and columns. You cannot draw an edge around six columns when the table only has five columns.

Author:  v_k [ Sun Jun 18, 2017 10:25 am ]
Post subject:  Re: Pdfsharp and tables

Ok, and I looked Migradoc source to help me.

this.table.SetEdge(a, b, c, d, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
Image
If I understood, a & b is the first line/column and c & d, the last line/column.

For the example (yeah, Excel powa), code is
Code:
this.table.SetEdge(0, 0, 2, 6, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
// with Excel coords
//this.table.SetEdge(A1.x, A1.y, C7.x, C7.y, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);


It's good ?

Author:  Thomas Hoevel [ Mon Jun 19, 2017 8:17 am ]
Post subject:  Re: Pdfsharp and tables

Hi!

I guess you will need "(0, 0, 3, 7, ...)" instead of "(0, 0, 2, 6, ...)".
You will not get an exception if the values are too small, so it is safe to try "2, 6" first.
Parameters three and four are the count of columns in the frame, not the co-ordinates of the lower right point.

Author:  v_k [ Mon Jun 19, 2017 8:54 am ]
Post subject:  Re: Pdfsharp and tables

OK, thanks :)

Author:  v_k [ Mon Jun 19, 2017 9:46 am ]
Post subject:  Re: Pdfsharp and tables

hmm, an another problem (the last ? :mrgreen: )
I have 4 persons, in 4 cities :
  • John in New-York
  • Tamara, Toronto
  • Emily, Paris
  • Tim, Madrid

With this code :
Code:
this.table.SetEdge(0, 0, this.table.Columns.Count, this.table.Rows.Count, Edge.Box, BorderStyle.Single, 0.75);
// this.table.Columns.Count = 2
// this.table.Rows.Count = 5

// first cell in first line :
// this.table.Rows.Items[1].Cells.Items[0].Elements.Items[0].Elements.Items[0].Content =  "John"


But when the PDF is generated :

Image

Why ?

EDIT : it's okay, my fault, I have a error with columns headers :
Code:
row.Cells[i].MergeDown = 1;


With 0, it's better :)

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