PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Nov 05, 2025 9:54 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Jul 03, 2013 12:20 pm 
Offline

Joined: Wed Jul 03, 2013 10:54 am
Posts: 5
Hi,

I have table cells where I add a paragraph.

To this paragraph, I'm adding an image and some text.

While the image respects vertical alignment settings (for example top aligned) in the cell, the text is always at the bottom of the image. How do I get the text to be for example top or center aligned?

The code looks like this:

Code:
paragraph = row.Cells[3].AddParagraph();
paragraph.AddImage("filename"));
paragraph.AddText("Some text");


Thanks in advance!


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 03, 2013 1:34 pm 
Offline
PDFsharp Guru
User avatar

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

MigraDoc treats the image like a character. Text will be to the right of the image if it fits (text vertically aligned at the bottom of the image) or below the image.
Add the text before the image and it will be the other way around.

Search for "WrapStyle.Through" for other options (text layouter will then ignore the image).

See also:
viewtopic.php?p=6820#p6820
viewtopic.php?p=5267#p5267

What are you trying to achieve?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 03, 2013 1:52 pm 
Offline

Joined: Wed Jul 03, 2013 10:54 am
Posts: 5
Look at the attached image file for what I'm trying to achieve.
I want the text 'Regular' to be vertically centered like the text 'Snowboard Standposition' so that both texts are on the same line.

I tried using "WrapStyle.Through" before but it didn't seem to change anything.


Attachments:
Untitled.gif
Untitled.gif [ 1.98 KiB | Viewed 28522 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 03, 2013 3:25 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
claus.net wrote:
I tried using "WrapStyle.Through" before but it didn't seem to change anything.
Well, you'll need some more tricks.
Maybe "image.RelativeVertical = RelativeVertical.Paragraph" will get you further.
You'll have to set the height of the row to make room for the image.
You'll have to add non-breaking spaces at the start of your text to move the text to the right of your image.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 04, 2013 7:47 am 
Offline

Joined: Wed Jul 03, 2013 10:54 am
Posts: 5
Thanks for your help!

Unfortunately, I tried everything you suggested but nothing seems to change. It still looks like in the image I attached earlier.

I even tried adding the image directly to the cell and the text in a paragraph but then, regardless of what I do, the text is always above or below the image.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 04, 2013 8:15 am 
Offline

Joined: Wed Jul 03, 2013 10:54 am
Posts: 5
What I also don't understand: I tried using a TextFrame instead of an image in order to see if I could maybe wrestle the frame and the text to the correct positions by using absolute positioning. After all, they are both shapes (the Image and TextFrame I mean), right?

So when I set "WrapStyle.Through" for the frame, the text paragraph is still influenced by settings like "DistanceTop" or "DistanceBottom" of the frame. I thought setting WrapStyle to "Through" would let you position the shape freely without altering the positions of other elements?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 04, 2013 9:25 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
claus.net wrote:
After all, they are both shapes (the Image and TextFrame I mean), right?
Right, so there is no need to put the image into a textframe to position it.

Maybe I can give it a try later today.

Could you send me a DDL file of your table? Might save me some time. Should be small, just ZIP it and attach it here. Please include the image.
http://www.pdfsharp.net/wiki/MigraDocDDL.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 04, 2013 4:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
It seems that floating images inside table cells do not work as intended.

As a workaround, I used a separate column for the image.

My test code:
Code:
var table = section.AddTable();
table.AddColumn("7cm");
table.AddColumn("12mm");
table.AddColumn("7cm");

var row = table.AddRow();
var paragraph = row.Cells[0].AddParagraph("First Column");
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;

var image = row.Cells[1].AddImage(@"C:\Users\thho\Pictures\ProgMan.png");
image.Height = "10mm";
paragraph = row.Cells[2].AddParagraph();
paragraph.AddText(" Second Column");
row.Cells[2].VerticalAlignment = VerticalAlignment.Center;
row.Cells[1].Borders.Right.Visible = false;
row.Cells[2].Borders.Left.Visible = false;
table.Borders.Width = 1;


And the results:
Attachment:
DummyColumn.png
DummyColumn.png [ 5.68 KiB | Viewed 28502 times ]


You can set the borders to make the column invisible.
For rows that don't have an image, you can set MergeRight to 1 and put the text into the image column. Same for header row.

I hope this helps.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 05, 2013 6:49 am 
Offline

Joined: Wed Jul 03, 2013 10:54 am
Posts: 5
Yeah, that's what I ended up doing as a workaround, too.

It would be nice if the slightly simpler way would work as intended but at least we have the ability to work around this issue.

Thanks for your help!


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

All times are UTC


Who is online

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