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

Overlap/sorround a text with an Image
http://forum.pdfsharp.com/viewtopic.php?f=2&t=1246
Page 1 of 1

Author:  lol_b [ Fri Jul 09, 2010 5:52 pm ]
Post subject:  Overlap/sorround a text with an Image

Hi guys,

I would find a solution for this little problem.
Suppose I have a percentage number: 45%. Now, I would sorround it whit a circle. The circle has to include the number, but the number has to remain visible. The circle which I use is transparent inside, instead the border has a red color. I must use the image and not a circle painted with pdfsharp. I think this last solution will work.

I hope I explain the problem in the right manner. Thank you in advance. Regards.

Update:

* PDFsharp or MigraDoc Foundation BOTH
* GDI+ or WPF build WPF build
* the version of PDFsharp/MigraDoc Foundation 1.3

Author:  Thomas Hoevel [ Mon Jul 12, 2010 7:49 am ]
Post subject:  Re: Overlap/sorround a text with an Image

Hi!
lol_b wrote:
I hope I explain the problem in the right manner.

I'm not sure if I understand the problem.

You can use images with transparency (PDF version 1.4 and higher).
You can draw circles with transparency (PDF version 1.4 and higher).

You don't need transparency if you draw the text (e. g. "45 %") on top of the circle ...

Author:  lol_b [ Mon Jul 12, 2010 10:24 am ]
Post subject:  Re: Overlap/sorround a text with an Image

Thank you Thomas.

I would know if it is possible to overlap an image and a text inside the same paragraph? The image has to contain the text.

Update: I've attached an image for clarify my needs. Now, I use only Migradoc and not PdfSharp.

Attachment:
image.png
image.png [ 11.12 KiB | Viewed 12376 times ]

Author:  Thomas Hoevel [ Mon Jul 12, 2010 1:10 pm ]
Post subject:  Re: Overlap/sorround a text with an Image

Images are Shapes and can be positioned in various ways: incl. relative position to the paragraph.
See members Left, Top, RelativeVertical, RelativeHorizontal, etc.

You can put the text in textframe (also a Shape). Or have it in a paragraph and position it with SpaceBefore.

Author:  lol_b [ Mon Jul 12, 2010 5:47 pm ]
Post subject:  Re: Overlap/sorround a text with an Image

Thank you Thomas. Very helpful.

Could you explain me what is a text frame? Could you provide an exampe to overlap text over an image?

And, finally, where I could find the migradoc api documentation?

Thank you for your attention.

Author:  Thomas Hoevel [ Tue Jul 13, 2010 7:52 am ]
Post subject:  Re: Overlap/sorround a text with an Image

Re: TextFrame:
viewtopic.php?p=3133#p3133

Re: API documentation:
http://pdfsharp.codeplex.com/releases/view/37054

Author:  lol_b [ Tue Jul 13, 2010 8:10 am ]
Post subject:  Re: Overlap/sorround a text with an Image

Thank you Thomas. The problem is that my overlapped element is inside a cell table.

Do I have to follow the same guide lines? Thanks again.

Update: The element is inside the cell and must have a centered position (relative to the cell which contains it).
The element is composed by two element: a text and an image.

I've tried with this code but doesn't work... :cry:
Code:
TextFrame textFrame = new TextFrame();
textFrame.Left = ShapePosition.Center;
textFrame.Top = ShapePosition.Center;
textFrame.RelativeVertical = RelativeVertical.Line;
textFrame.RelativeHorizontal = RelativeHorizontal.Column;

Paragraph paragraph = textFrame.AddParagraph("45 %");

Image image = textFrame.AddImage("/dir/img.png");
image.LockAspectRatio = true;
image.RelativeVertical = RelativeVertical.Margin;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Center;
image.Left = ShapePosition.Center;
image.WrapFormat.Style = WrapStyle.Through;

row1.cells[2].Add(textFrame);

Author:  Thomas Hoevel [ Tue Jul 13, 2010 11:17 am ]
Post subject:  Re: Overlap/sorround a text with an Image

lol_b wrote:
The problem is that my overlapped element is inside a cell table.

The real problem is: you didn't mention that right from the start.

I said you can use a textframe for the text.
The image is a shape, the textframe is a shape - no need to place the image in a shape.

There's a lot else you don't mention.
You say the code snippet doesn't work - but you don't say what it does.

Do you really need the text "45 %" in the table cell?
I'd take it out of the cell and put it in a textframe.

First add the image (with AddImage) and put it where you want to have it, then add the textframe (with AddTextFrame) and put it at the same place and your done.

Author:  lol_b [ Tue Jul 13, 2010 4:28 pm ]
Post subject:  Re: Overlap/sorround a text with an Image

Thank you for your attention Thomas.

Quote:
Do you really need the text "45 %" in the table cell?

Yes, I need it.

I'll try to summarize the problem I would to fix.

I have a table. The table contains cells. Each cell contains a number (the text is contained in a paragraph element).
In a specific column of the table, each cell (that belongs to this column) contains an element composed by text and image (see the above posted image). My needs are:

    - insert the text and the image like the above image, where the image overlap the text or viceversa;
    - center the position of the text and the image relative to the container (the cell in this case), the image and the text have to be positioned in the middle of the cell.

Is it possible? What type of element can I utilize (for composing a text plus an image) and insert it into the cell? Could you provide some guide lines?
Thank you again. Best regards.

P.S. I hope I've explained the problem in the right manner. :roll:

Author:  Thomas Hoevel [ Wed Jul 14, 2010 7:46 am ]
Post subject:  Re: Overlap/sorround a text with an Image

I'd try using cell.AddImage to add the image (set the size only, nothing else).
Then I'd add the text using cell.AddTextFrame. Theoretically you can position the textframe so that it overlaps the image.

A different approach: use the cell (with the text) as placeholder and add the image later using PDFsharp.
Currently you have to add a method to MigraDoc to make this work as described here:
viewtopic.php?p=1960#p1960

Author:  lol_b [ Wed Jul 14, 2010 9:37 am ]
Post subject:  Re: Overlap/sorround a text with an Image

Quote:
I'd try using cell.AddImage to add the image (set the size only, nothing else).
Then I'd add the text using cell.AddTextFrame. Theoretically you can position the textframe so that it overlaps the image.


Thank you for your suggestion, but the image can't be positioned in the center of the cell...

Code:
...
row1.Cells[4].Add(disposeImage());
...
private static Image disposeImage()
{
Image img = new Image("images/circle.png");
img.WrapFormat.Style = WrapStyle.Through;
img.Left = ShapePosition.Center; <--- the image isn't positioned in the center of the cell
return img;
}


I'll try also to put the image into a paragraph. The image is positioned in the center of the cell but when I add the textframe it doesn't work. Here a code snippet:

Code:
....
row1.Cells[4].Add(disposeImage());
row1.Cells[4].Add(disposeText());
....
private static Paragraph disposeImage()
{
Paragraph paragraph = new Paragraph();
paragraph.Format.Alignment = ParagraphAlignment.Center;

Image img = new Image("images/circle.png");
img.ScaleWidth = 0.7;
img.LockAspectRatio = true;
img.WrapFormat.Style = WrapStyle.Through;

paragraph.Add(img);

return paragraph;
}

private static TextFrame disposeText()
{
TextFrame frame = new TextFrame();
frame.AddParagraph("45 %");
frame.MarginLeft = "1.3cm";

frame.WrapFormat.Style = WrapStyle.Through;

return frame;
}

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