PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

multi-formatted text
https://forum.pdfsharp.net/viewtopic.php?f=2&t=762
Page 1 of 1

Author:  Soldier-B [ Tue Jun 16, 2009 6:31 pm ]
Post subject:  multi-formatted text

Does anybody know of a somewhat easy to implement method of rendering text at a specific location on the document where the text could have different formatting (i.e.: text changes color, size, font, character/line spacing)? I'm having a difficult time wrapping my head around this one. Any help is much appreciated!

- B

Author:  Thomas Hoevel [ Thu Jun 18, 2009 8:50 am ]
Post subject:  Re: multi-formatted text

I'm not sure if I fully understand what you need.

MigraDoc can do a lot (use AddParagraph(), AddFormattedText() etc.).

Author:  Soldier-B [ Thu Jun 18, 2009 2:27 pm ]
Post subject:  Re: multi-formatted text

What I'm trying to accomplish is to render formatted text at a specific location on the document and have it wrap in a predefined rectangle, but the text might not have the same style for the entire block. I have to parse a small subset of html and render that. The problem is that with MigraDoc I couldn't find any way to position the paragraph or set a bounding rectangle for it. Using just PdfSharp I would have to render the text character by character because I haven't found a way to render text when the formatting changes. Here's a sample html block that shows what I'm trying to render:
Code:
<P ALIGN="CENTER">
   <FONT FACE="_Times" SIZE="32" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">
      This is one long sentence that will wrap to <U>multiple lines</U> and center any text.
   </FONT>
</P>
<P ALIGN="LEFT">
   <TEXTFORMAT LEADING="18">
      <FONT FACE="_Times" SIZE="32" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">
         This<FONT COLOR="#FF0000"> text </FONT>should be left aligned.
      </FONT>
   </TEXTFORMAT>
</P>
<P ALIGN="JUSTIFY">
   <FONT FACE="_Times" SIZE="32" COLOR="#FFFFFF" LETTERSPACING="2.2" KERNING="0">
      <FONT COLOR="#0000FF">But</FONT> this should be <FONT COLOR="#00FF00">justified</FONT>. So should this.
   </FONT>
</P>


For that example I have a document that I need to render that text to. I know what x and y position I need to put the text at and I know the size of the bounding box the text needs to wrap in. I'm just not sure which approach is the best at this point.

Thanks in advance for any help Thomas.

Author:  Thomas Hoevel [ Thu Jun 18, 2009 3:00 pm ]
Post subject:  Re: multi-formatted text

With MigraDoc you could set PageSetup to the allowed rectangle.
If the document renders to one page, the text does fit.
If it gives two or more pages, the text doesn't fit. (You might try again with smaller font size ...)

MigraDoc renders to pages, not to rectangles - so give it the correct page size.

Author:  Soldier-B [ Fri Jun 19, 2009 6:41 pm ]
Post subject:  Re: multi-formatted text

Thanks for your suggestion Thomas, I've come up with a reliable solution to my original problem. I do have one other question though. Is there any way to set the amount of leading for an XFont object?

Author:  Thomas Hoevel [ Tue Jun 23, 2009 7:57 am ]
Post subject:  Re: multi-formatted text

Fonts are not my area of expertise.
If either GDI+ or WPF (or both) support such a leading then we should add a way to set that.

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