PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Table https://forum.pdfsharp.net/viewtopic.php?f=2&t=1437 |
Page 1 of 1 |
Author: | zolectronic [ Wed Nov 24, 2010 10:24 am ] |
Post subject: | Table |
Hello, I'm french and I have a problem. I use the Table element and if the table is taller than page, I will want pass at the next page. Have you got a solution for me ? Thank you and sorry for my english |
Author: | Thomas Hoevel [ Wed Nov 24, 2010 11:14 am ] |
Post subject: | Re: Table |
Tables automatically break to the next page. But: table rows do not break, so make sure each row fits on a single page. And don't mark data rows as header rows. |
Author: | zolectronic [ Wed Nov 24, 2010 12:14 pm ] |
Post subject: | Re: Table |
I use the table with the associate pdfsharp document and the Tables don't automatically break to the next page. It's normal ? |
Author: | Thomas Hoevel [ Wed Nov 24, 2010 12:23 pm ] |
Post subject: | Re: Table |
zolectronic wrote: It's normal? Please be more specific what you are using. MigraDoc tables break automatically. AFAIK there are no PDFsharp tables. MigraDoc sample: http://www.pdfsharp.net/wiki/Invoice-sample.ashx |
Author: | zolectronic [ Wed Nov 24, 2010 12:32 pm ] |
Post subject: | Re: Table |
Here it's my code : Code: // You always need a MigraDoc document for rendering. Document doc = new Document(); Section section = doc.AddSection(); MigraDoc.DocumentObjectModel.Tables.Table table; table = section.AddTable(); table.Style = "Table"; table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black; table.Borders.Width = 0.25; table.Borders.Left.Width = 0.5; table.Borders.Right.Width = 0.5; table.Rows.LeftIndent = 0; Row row = null; for (int i = 0; i < 5; i++) { Column column = table.AddColumn(110); column.Format.Alignment = ParagraphAlignment.Center; } for (int j = 0; j < 50; j++) { row = table.AddRow(); for (int i = 0; i < 5; i++) { if (j > 0) { row.Borders.Bottom.Width = 0; row.Borders.Top.Width = 0; row.Cells[i].Format.Font.Bold = false; } else { row.Borders.Bottom.Width = 1; row.Borders.Top.Width = 1; //row.Height = 20; row.Cells[i].Format.Font.Bold = true; } row.Cells[i].AddParagraph(j + " Item \n\n oh"); row.Cells[i].Format.Alignment = ParagraphAlignment.Center; row.Cells[i].VerticalAlignment = VerticalAlignment.Center; } } MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); double Y = 325; double X = 20; docRenderer.RenderObject(gfx, X, Y, "12cm", table); It's a test to view if tables break automatically. Do you see the problem ? |
Author: | Thomas Hoevel [ Wed Nov 24, 2010 1:12 pm ] |
Post subject: | Re: Table |
I'm not familiar with RenderObject. I'd simply call RenderPage like this sample does: http://www.pdfsharp.net/wiki/MixMigraDo ... Page_Two_2 Or more simple: just call RenderDocument as shown here: http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx |
Author: | zolectronic [ Mon Nov 29, 2010 9:42 am ] |
Post subject: | Re: Table |
I tried but i don't successful. Anybody have a solution for me please ? |
Author: | jeffhare [ Wed Dec 01, 2010 10:54 pm ] |
Post subject: | Re: Table |
Tables should break when a Row doesn't fit on a page. As Thomas said, if a Row (Cell actually) is taller than the printable area of a page, it will not 'continue' this row on the next page. It will, however continue the NEXT row on the next page. This is the code I use to render my doc after writing tables. Code: // ... Code to create the doc with table ... // pdfDoc.DefaultPageSetup.PageFormat = PageFormat.Letter; pdfDoc.DefaultPageSetup.Orientation = Orientation.Portrait; pdfDoc.DefaultPageSetup.BottomMargin = "1cm"; pdfDoc.DefaultPageSetup.TopMargin = "1cm"; pdfDoc.DefaultPageSetup.HeaderDistance = 0; pdfDoc.DefaultPageSetup.FooterDistance = 0; pdfDoc.DefaultPageSetup.LeftMargin = "1cm"; pdfDoc.DefaultPageSetup.RightMargin = "1cm"; PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.None) { Document = pdfDoc }; renderer.RenderDocument(); renderer.Save(FilePath); |
Author: | zolectronic [ Fri Dec 03, 2010 10:29 am ] |
Post subject: | Re: Table |
Can you give me a sample for create a table on many pages with migraDoc and PDFSharp with rendering for web, because i don't arrive... Thanks you very much |
Author: | Remis [ Fri Dec 03, 2010 6:52 pm ] |
Post subject: | Re: Table |
zolectronic, I don't have a chance to help you with sample code, but I took a look at what RenderObject is supposed to do. http://gitorious.org/pdfsharp/pdfsharp/commit/ffcea5d7facfc166be2a3993fed5ea0548e08421 /// <summary> 188 /// Renders a single object to the specified graphics object at the given point. 189 /// </summary> 190 /// <param name="graphics">The graphics object to render on.</param> 191 /// <param name="xPosition">The left position of the rendered object.</param> 192 /// <param name="yPosition">The top position of the rendered object.</param> 193 /// <param name="width">The width.</param> 194 /// <param name="documentObject">The document object to render. Can be paragraph, table, or shape.</param> 195 /// <remarks>This function is still in an experimental state.</remarks> 196 public void RenderObject(XGraphics graphics, XUnit xPosition, XUnit yPosition, XUnit width, DocumentObject documentObject) 197 { ... The signature and comments reveals (IMHO) it's supposed to draw a graphics object at some position in the page. Can be used with elements that fit on a single page. This is not what you want. You need page breaks. Therefore I suggest you should not use RenderDocument() instead of RenderObject(). Look at samples Thomas Hövel gave links to. In French: double Y = 325; double X = 20; docRenderer.RenderObject(gfx, X, Y, "12cm", table); docRenderer.RenderDocument(); |
Author: | zolectronic [ Sat Dec 04, 2010 12:38 pm ] |
Post subject: | Re: Table |
Thank you, i did see my error, the problem was in the save in the stream of the migradoc document. |
Author: | zolectronic [ Fri Dec 10, 2010 8:23 am ] |
Post subject: | Re: Table |
The problem is not resolved. It's impossible to draw a table and a XGraphic on same page with RendrerDocument. Can you show me an example with a Table and an Xgraphic object please ![]() |
Author: | Remis [ Tue Dec 14, 2010 5:19 pm ] |
Post subject: | Re: Table |
zoletronic, seem you're right: there is no easy way to render Migradoc tables over PDF pages. Try to play with this code: Code: static void Main()
{ Document doc = new Document(); Section section = doc.AddSection(); MigraDoc.DocumentObjectModel.Tables.Table table; table = section.AddTable(); table.Style = "Table"; table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black; table.Borders.Width = 0.25; table.Borders.Left.Width = 0.5; table.Borders.Right.Width = 0.5; table.Rows.LeftIndent = 0; Row row = null; for (int i = 0; i < 5; i++) { Column column = table.AddColumn(110); column.Format.Alignment = ParagraphAlignment.Center; } for (int j = 0; j < 50; j++) { row = table.AddRow(); for (int i = 0; i < 5; i++) { if (j > 0) { row.Borders.Bottom.Width = 0; row.Borders.Top.Width = 0; row.Cells[i].Format.Font.Bold = false; } else { row.Borders.Bottom.Width = 1; row.Borders.Top.Width = 1; //row.Height = 20; row.Cells[i].Format.Font.Bold = true; } row.Cells[i].AddParagraph(j + " Item \n\n oh"); row.Cells[i].Format.Alignment = ParagraphAlignment.Center; row.Cells[i].VerticalAlignment = VerticalAlignment.Center; } } MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); PdfDocument pdfDocument = new PdfDocument(); { // For clarity we use point as unit of measure in this sample. // A4 is the standard letter size in Germany (21cm x 29.7cm). XRect A4Rect = new XRect(0, 0, A4Width, A4Height); int pageCount = docRenderer.FormattedDocument.PageCount; for (int idx = 0; idx < pageCount; idx++) { PdfPage page = pdfDocument.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; XRect rect = A4Rect; // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations. XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point); // Draw page border for better visual representation gfx.DrawRectangle(XPens.LightGray, A4Rect); // Render the page. Note that page numbers start with 1. docRenderer.RenderPage(gfx, idx + 1); // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document. // Pop the previous graphical state gfx.EndContainer(container); } } string filename = Guid.NewGuid().ToString("D").ToUpper() + ".pdf"; // Save the document... pdfDocument.Save(filename); // ...and start a viewer Process.Start(filename); } |
Author: | Remis [ Tue Dec 14, 2010 7:14 pm ] |
Post subject: | Re: Table |
PS. Still, this using XGraphics seems for me as diving into too low level (MsPaint level, see http://uncyclopedia.wikia.com/wiki/MS_Paint) if you need only table but no page watermarks, please check PdfDocumentRenderer (http://model-xtractor.com/web/Viewer.aspx?id=569 or http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx). With PdfDocumentRenderer you'll stay at MsWord level (http://uncyclopedia.wikia.com/wiki/MS_Word). |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |