PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue May 07, 2024 9:17 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: multi-formatted text
PostPosted: Tue Jun 16, 2009 6:31 pm 
Offline
User avatar

Joined: Tue Oct 14, 2008 6:15 pm
Posts: 32
Location: USA
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


Top
 Profile  
Reply with quote  
 Post subject: Re: multi-formatted text
PostPosted: Thu Jun 18, 2009 8:50 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
I'm not sure if I fully understand what you need.

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: multi-formatted text
PostPosted: Thu Jun 18, 2009 2:27 pm 
Offline
User avatar

Joined: Tue Oct 14, 2008 6:15 pm
Posts: 32
Location: USA
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: multi-formatted text
PostPosted: Thu Jun 18, 2009 3:00 pm 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: multi-formatted text
PostPosted: Fri Jun 19, 2009 6:41 pm 
Offline
User avatar

Joined: Tue Oct 14, 2008 6:15 pm
Posts: 32
Location: USA
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: multi-formatted text
PostPosted: Tue Jun 23, 2009 7:57 am 
Offline
PDFsharp Guru
User avatar

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

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

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