PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 26, 2024 9:22 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Table
PostPosted: Wed Nov 24, 2010 10:24 am 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Nov 24, 2010 11:14 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Nov 24, 2010 12:14 pm 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
I use the table with the associate pdfsharp document and the Tables don't automatically break to the next page.

It's normal ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Nov 24, 2010 12:23 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Nov 24, 2010 12:32 pm 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
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 ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Nov 24, 2010 1:12 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Mon Nov 29, 2010 9:42 am 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
I tried but i don't successful.
Anybody have a solution for me please ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Wed Dec 01, 2010 10:54 pm 
Offline
Supporter
User avatar

Joined: Thu May 27, 2010 7:40 pm
Posts: 59
Location: New Hampshire, USA
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);


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Fri Dec 03, 2010 10:29 am 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Fri Dec 03, 2010 6:52 pm 
Offline

Joined: Wed Nov 11, 2009 9:40 am
Posts: 17
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();

_________________
Regards,
Remigijus Pankevičius


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Sat Dec 04, 2010 12:38 pm 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
Thank you, i did see my error, the problem was in the save in the stream of the migradoc document.


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Fri Dec 10, 2010 8:23 am 
Offline

Joined: Thu Aug 19, 2010 7:58 pm
Posts: 10
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 :?:


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Tue Dec 14, 2010 5:19 pm 
Offline

Joined: Wed Nov 11, 2009 9:40 am
Posts: 17
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);
     }


_________________
Regards,
Remigijus Pankevičius


Top
 Profile  
Reply with quote  
 Post subject: Re: Table
PostPosted: Tue Dec 14, 2010 7:14 pm 
Offline

Joined: Wed Nov 11, 2009 9:40 am
Posts: 17
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).

_________________
Regards,
Remigijus Pankevičius


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 103 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