PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 3:04 am

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: Sat Oct 27, 2012 8:06 pm 
Offline

Joined: Sat Oct 27, 2012 7:58 pm
Posts: 4
Hi

At first, let me congratulate you to MigraDoc + SharpPDF, two great products. I started using them yesterday and have come quite far already. Sometimes it requires a Change in thinking but I haven't come across a real Problem yet (except this one :) ).

I try to draw a table with 8 columns where each cell only contains some numbers. Therefore I'd like to write the headers rotated by 90°. I got this working, but there is an unusual large space after the text and I do not know where this comes from. I made a Picture of the resulting PDF so you can see what I mean.

The code Looks like this:
Code:

            Table t = InitializeTable(doc, s, 8, Unit.FromMillimeter(15));
            t.AddHeaderRowToTable(descs, colors);


Where the second function is an Extension method to the MigraDoc "Table".

Code:
       
        private static Table InitializeTable(Document doc, Section s, int nrColumns, Unit colWidth)
        {
            Table t = s.AddTable();
            t.Borders = new Borders {Visible = true, Width = 0.1};

            for (int i = 0; i < nrColumns; i++)
            {
                t.AddColumn(colWidth);
            }

            double leftIndentForTable = (doc.DefaultPageSetup.PageWidth.Millimeter - doc.DefaultPageSetup.LeftMargin.Millimeter - doc.DefaultPageSetup.RightMargin.Millimeter - (t.Columns.Count * t.Columns[0].Width.Millimeter)) / 2;
            t.Rows.LeftIndent = Unit.FromMillimeter(leftIndentForTable);

            return t;
        }

public static void AddHeaderRowToTable(this Table t, List<string> descriptions, List<Color> backgroundColors)
        {
            Row rFirst = t.AddRow();
            //rFirst.HeadingFormat = true;

            for (int i = 0; i < descriptions.Count; i++)
            {
                TextFrame tr = rFirst.Cells[i].AddTextFrame();
                rFirst.Cells[i].Shading.Color = backgroundColors[i];
                rFirst.Cells[i].Shading.Visible = true;
                rFirst.Cells[i].Format.Alignment = ParagraphAlignment.Center;
                tr.Orientation = TextOrientation.Upward;
               
                tr.AddParagraph(descriptions[i]);

            }
        }


Do you have any idea what I am doing wrong? Why is there so much space above the table Header?

btw: Embedding Graphs made by OxyPlot works very nicely.


Attachments:
2012-10-27_21-57-11.png
2012-10-27_21-57-11.png [ 106.48 KiB | Viewed 7696 times ]
Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 27, 2012 8:48 pm 
Offline

Joined: Sat Oct 27, 2012 7:58 pm
Posts: 4
Update (but not yet resolved):

It seems to have to do with the TextFrame. If I do not add a Textframe but only a Paragraph, the Height appears to be fine.
Yet, I Need to add the textframe because I want the text rotated ;)

Strange.


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 28, 2012 4:17 pm 
Offline

Joined: Sat Oct 27, 2012 7:58 pm
Posts: 4
I also forgot to add the Version numbers I'm using:
PdfSharp: 1.32.2602.0
MigraDoc: 1.32.3879.0
(These are the Version which NuGet retrieved)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 10:05 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!
somnatic wrote:
Why is there so much space above the table Header?
I don't know.
Maybe the row height is determined by the width of the textframes. You do not set the width - and I don't know which value will be used.

Try setting the width of the textframe (maybe to 1 cm) to see if that makes a difference.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2012 8:05 pm 
Offline

Joined: Sat Oct 27, 2012 7:58 pm
Posts: 4
Hi

Been there, done that:


Code:
TextFrame tr = rFirst.Cells[i].AddTextFrame();
tr.Width = Unit.FromMillimeter(15);
tr.Height = Unit.FromMillimeter(15);
(tried this in all combinations)


Basically, setting the Height has an effect, but my text will then overflow if it's too small or the frame will be too large.
Setting the Width, does not have an effect at all.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 10:34 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
somnatic wrote:
Basically, setting the Height has an effect, but my text will then overflow if it's too small or the frame will be too large.
You can use gfx.MeasureString() from PDFsharp to calculate the width (in your case height) a specific text will need. You may have to add a few points for border and padding.
And if you set the correct width for the paragraph in the textframe, the text should wrap to the next line (only needed if you want long labels to wrap).

IMHO setting the Height to a value calculated from the length of label texts is the way to go.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 05, 2013 2:49 pm 
Offline

Joined: Thu Dec 05, 2013 2:45 pm
Posts: 4
somnatic wrote:
Hi
btw: Embedding Graphs made by OxyPlot works very nicely.


Hi, Can you post an example of how you got this working please ?

I'm trying to use MigraDoc with OxyPlot, but can't see a way to render OxyPlot to a MigraDoc document.
I can get OxyPlot to render to a BitmapSource, but can't find a way to add that to a migradoc (without saving it as a temp file first, which I don't like really)

Thanks in advance


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 288 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