PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

image to left of text
http://forum.pdfsharp.com/viewtopic.php?f=2&t=2774
Page 1 of 1

Author:  nitsuj [ Thu Mar 27, 2014 6:53 am ]
Post subject:  image to left of text

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 12143 times ]

Author:  Thomas Hoevel [ Thu Mar 27, 2014 12:46 pm ]
Post subject:  Re: image to left of text

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.

Author:  nitsuj [ Thu Mar 27, 2014 1:17 pm ]
Post subject:  Re: image to left of text

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.

Author:  adandrea [ Tue Apr 08, 2014 9:26 pm ]
Post subject:  Re: image to left of text

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

Author:  Thomas Hoevel [ Wed Apr 09, 2014 7:37 am ]
Post subject:  Re: image to left of text

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

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/