PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 8:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Wed Jan 21, 2015 2:08 pm 
Offline

Joined: Wed Jan 21, 2015 1:06 pm
Posts: 4
I am probably doing something completely wrong as I can't think that this should be that difficult!
Here's my problem (using Migradoc and pdfsharp):
I am creating a table and this tables must have borders (not just external but 'gridlines' as well)
The issue that some of the text in the cell is larger than the cell width and it wraps - and that's fine.
Problem is that the borders (despite if I use borders for the whole table or just for each row or each column, DO NOT detect this so I am ending with tables like this- when using:
Code:
tabBlds.Format.Borders.Width = 0.5;

Attachment:
tab1.png
tab1.png [ 19.41 KiB | Viewed 10940 times ]

or this when using:
Code:
Column column = tabBlds.AddColumn("4.5cm");
column.Format.Borders.Right.Width = 1.0;
column = tabBlds.AddColumn("2.5cm");
column.Format.Borders.Right.Width = 1.0;
column = tabBlds.AddColumn("2.5cm");
column.Format.Borders.Right.Width = 1.0;
column = tabBlds.AddColumn("2.5cm");
column.Format.Borders.Right.Width = 1.0;
column = tabBlds.AddColumn("4cm");
column.Format.Borders.Right.Width = 1.0;
column = tabBlds.AddColumn("3cm");
column.Format.Borders.Right.Width = 0;


Attachment:
tab2.png
tab2.png [ 18.06 KiB | Viewed 10940 times ]


I have event tried to add some 'invisible' paragraphs (just text in white) so all cells have the same number of lines and that sort of works for the header row but not for the rest as I am reading data from a database for this and not sure how long the text will.

Surely there must be an easier way??
Many thanks in advance,
Pano


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 21, 2015 2:44 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!

I presume the root of the problem is with the code you are not showing.

Our application works fine and the Invoice sample doesn't show this behavior either.
http://www.pdfsharp.net/wiki/Invoice-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 21, 2015 3:15 pm 
Offline

Joined: Wed Jan 21, 2015 1:06 pm
Posts: 4
Most probably! Ok, I will try to make a sample project and show you the full code I am using. But as far as you are aware there is no 'trick' to this- right? It should just work and respect the text wrapping?


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 21, 2015 4:40 pm 
Offline

Joined: Wed Jan 21, 2015 1:06 pm
Posts: 4
Ok, so here's some sample code- what am I doing wrong?

Code:
Document document = new Document();

            PageSetup myPageSetup = new PageSetup();
            myPageSetup = document.DefaultPageSetup.Clone();
            myPageSetup.FooterDistance = "0.1cm";
            myPageSetup.LeftMargin = Unit.FromCentimeter(0.5);
            myPageSetup.BottomMargin = Unit.FromCentimeter(1.0);
            myPageSetup.RightMargin = Unit.FromCentimeter(0.5);
            myPageSetup.TopMargin = Unit.FromCentimeter(5.5);
            DefineStyles();

            Section section = document.AddSection();
            Table tabBlds = section.AddTable();
            tabBlds.Format.Font.Size = "9";
            tabBlds.Format.Alignment = ParagraphAlignment.Center;
            //tabBlds.Format.Borders.Width = 1.0;
            tabBlds.Rows.LeftIndent = 0;
            tabBlds.LeftPadding = 0;
            tabBlds.RightPadding = 0;
            tabBlds.TopPadding = 0;
            tabBlds.BottomPadding = 0;
            Column column = tabBlds.AddColumn("4cm");
            column.Format.Borders.Right.Width = 1.0;
            column = tabBlds.AddColumn("2.5cm");
            column.Format.Borders.Right.Width = 1.0;
            column = tabBlds.AddColumn("2.5cm");
            column.Format.Borders.Right.Width = 1.0;
            column = tabBlds.AddColumn("2.0cm");
            column.Format.Borders.Right.Width = 1.0;
            column = tabBlds.AddColumn("4cm");
            column.Format.Borders.Right.Width = 1.0;
            column = tabBlds.AddColumn("3.0cm");
            column.Format.Borders.Right.Width = 0;

            Row row = tabBlds.AddRow();
            row.HeadingFormat = true;
            row.Format.Alignment = ParagraphAlignment.Center;

            row.Cells[0].AddParagraph("This text will fit in two lines - now!");
            //Paragraph p1 = new Paragraph();
            //p1.AddFormattedText("INVISIBLE TEXT");
            //p1.Format.Font.Color = Color.FromCmyk(0.0, 0.0, 0.0, 0.0);
            //row.Cells[0].Add(p1);

            row.Cells[1].AddParagraph("One liner 1");
            //row.Cells[1].Add(p1.Clone());
            //row.Cells[1].Add(p1.Clone());

            row.Cells[2].AddParagraph("One liner 2");
            //row.Cells[2].Add(p1.Clone());
            //row.Cells[2].Add(p1.Clone());

            row.Cells[3].AddParagraph("One liner 3");
            //row.Cells[3].Add(p1.Clone());
            //row.Cells[3].Add(p1.Clone());

            row.Cells[4].AddParagraph("One liner 4");
            //row.Cells[4].Add(p1.Clone());
            //row.Cells[4].Add(p1.Clone());

            row.Cells[5].AddParagraph("This text is long enough to fit in three lines");

            row = tabBlds.AddRow();
            row.HeadingFormat = false;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Borders.Top.Width = 1.0;

            row.Cells[0].AddParagraph("One liner 1");
            row.Cells[1].AddParagraph("This text will fit in two lines - now!");
            row.Cells[2].AddParagraph("This text is long enough to fit in three lines");
            row.Cells[3].AddParagraph("One liner 2");
            row.Cells[4].AddParagraph("One liner 3");
            row.Cells[5].AddParagraph("One liner 4");
           

            tabBlds.SetEdge(0, 0, tabBlds.Columns.Count, tabBlds.Rows.Count, Edge.Box, BorderStyle.Single, 1.0, Color.Empty);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
            // Set the MigraDoc document
            pdfRenderer.Document = document;

            // Create the PDF document
            pdfRenderer.RenderDocument();

            // Save the PDF document...
            string filename = string.Empty;

            // I don't want to close the document constantly...
            filename = "test-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
            pdfRenderer.Save("C:\\Development\\Geoktima\\out_pdf\\" + filename);


And here's the output:
Attachment:
tab3.png
tab3.png [ 12.46 KiB | Viewed 10937 times ]


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 22, 2015 12:16 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
OK, I get the same table you get.
I don't have a solution yet.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 22, 2015 12:31 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
I think you do nothing wrong.

When you set the border for each cell, the table will look right:
Code:
            for (int i = 0; i < 5; ++i)
                row.Cells[i].Borders.Right.Width = 1;


Setting the border for each cell should IMHO have the same effect, but lines are too short.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 23, 2015 2:09 pm 
Offline

Joined: Wed Jan 21, 2015 1:06 pm
Posts: 4
Yip- you are right. This works with all borders as well AND using padding (row and column borders don't when you specify padding).
Having said that in the end I used:
Code:
tabBlds.Format.Borders.Width = 1.0


Which does it in one go and seems to respect wrapped lines and padding. But many thanks again for your feedback. Cell border(-ing) will come in handy when trying to 'fine-tune' the borders


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 47 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