PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 27, 2024 7:13 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Fri Jul 09, 2010 5:52 pm 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 7:49 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
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 ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 10:24 am 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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 12365 times ]


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 1:10 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2010 5:47 pm 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 13, 2010 7:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
Re: TextFrame:
viewtopic.php?p=3133#p3133

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 13, 2010 8:10 am 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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);


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 13, 2010 11:17 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 13, 2010 4:28 pm 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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:


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 14, 2010 7:46 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3110
Location: Cologne, Germany
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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 14, 2010 9:37 am 
Offline

Joined: Thu Jul 08, 2010 2:59 pm
Posts: 8
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;
}


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

All times are UTC


Who is online

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