PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 1:31 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: image to left of text
PostPosted: Thu Mar 27, 2014 6:53 am 
Offline

Joined: Thu Mar 27, 2014 6:30 am
Posts: 5
I've been searching the forum, but can't find an answer to this maybe someone can point me in the right direction.

All I want todo is have an image to the left of a paragraph of text (see the attachment - top is what I want and bottom is what I am getting)

I have a bunch of text before and after this, but on this one paragraph I would like to have an image. The boiled down code I'm using is:

Code:
paragraph = section.AddParagraph();
string ImageArea = @"F:\pdfTest\";
Image image = paragraph.AddImage(ImageArea + "test.png");
image.Height = "2.5cm";
image.LockAspectRatio = true;           

image.RelativeVertical = RelativeVertical.Paragraph;
image.RelativeHorizontal = RelativeHorizontal.Margin;           
image.Top = ShapePosition.Top;
image.Left = 0;
           
image.WrapFormat.Style = WrapStyle.None;

paragraph.AddText("This is some text to the left of the image it also wraps at the bottom if it goes to long… This is some text to the left of the image it also wraps at the bottom if it goes to long… This is some text to the left of the image it also wraps at the bottom if it goes to long… This is some text to the left of the image it also wraps at the bottom if it goes to long… This is some text to the left of the image it also wraps at the bottom if it goes to long…");

paragraph = section.AddParagraph();
...


I've tried various changes to RelativeVertical,RelativeHorizontal, image.top and left but nothing makes a difference.

Any ideas would be great.


Attachments:
File comment: top what I want, bottom what I get
wraptext.JPG
wraptext.JPG [ 60.72 KiB | Viewed 10087 times ]
Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 27, 2014 12:46 pm 
Offline
PDFsharp Guru
User avatar

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

Add the image to the section, not the paragraph.

Code:
string ImageArea = @"C:\Users\...\";
Image image = section.AddImage(ImageArea + "<sample image>.png");
image.Width = "2.5cm";
image.LockAspectRatio = true;

image.RelativeHorizontal = RelativeHorizontal.Margin;

image.WrapFormat.Style = WrapStyle.Through;

var paragraph = section.AddParagraph();
paragraph.AddText("This is some text to the left of the image it also wraps at the bottom if it goes to long… " +
    "This is some text to the left of the image it also wraps at the bottom if it goes to long… " +
    "This is some text to the left of the image it also wraps at the bottom if it goes to long… " +
    "This is some text to the left of the image it also wraps at the bottom if it goes to long… " +
    "This is some text to the left of the image it also wraps at the bottom if it goes to long…");
paragraph.Format.LeftIndent = "2.6cm";
paragraph = section.AddParagraph();


Please note that MigraDoc cannot have text float around an image.
I set the left indent of the paragraph to prevent the text from overlapping the image.
Another option would be a table with two cells (two columns, one row) - one cell for the image, one cell for the text.

This will prevent overlapping between image and the following paragraphs.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 27, 2014 1:17 pm 
Offline

Joined: Thu Mar 27, 2014 6:30 am
Posts: 5
That fine, I'll use one of those options.

Shame about the non-support for floating images, but I susspect thats a larger/deeper technical issue that isn't easy to resolve.


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 08, 2014 9:26 pm 
Offline

Joined: Tue Apr 01, 2014 7:33 pm
Posts: 19
what kind of using assembilies did you use to get this to work? I just want to add an image into my page but keep getting "the name 'section' does not exist in current context and also "image is an ambiguous reference" I think I am mising some using or references but cant seem to add the right one. does anyone have some advice on how to add an image. this is the current code generating the pdf and ou can see where i am trying to add in the image. any advice or support would be greatly appreciated.

Code:
Code removed by moderator.


thank you so much


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 09, 2014 7:37 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
adandrea wrote:
any advice or support would be greatly appreciated.
No need to post a question in two threads at the same time.
See also:
viewtopic.php?f=2&t=2781&p=8086#p8086

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

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