PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 1:11 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Feb 08, 2012 6:44 pm 
Offline

Joined: Wed Feb 08, 2012 6:36 pm
Posts: 8
At the top of my document I have three Font's defined like this:

Code:
private Font headerFont = new Font("Arial", 13);
private Font titleFont = new Font("Clarendon", 20);
private Font normalFont = new Font("Arial", 10);


Then, at the beginning of a function I set their colors like this:

Code:
normalFont.Color = Colors.Black;
normalFont.Bold = false;
titleFont.Color = Color.Parse("0x43545E");
titleFont.Bold = true;
headerFont.Color = Color.Parse("0x43545E");
headerFont.Bold = true;


During the creation of my document, I do many calls like this (txtFr is a textframe):

Code:
var p = txtFr.AddParagraph("Header");
p.Format.Font = headerFont.Clone();

p = txtFr.AddParagraph("Content");
p.AddLineBreak();
p.AddLineBreak();
p.Format.Font = normalFont.Clone();

p = txtFr.AddParagraph("Another Title");
p.Format.Font = titleFont.Clone();


Anything that I set to normalFont seems to be working just fine.

The first time I use headerFont it works fine. Second (third, fourth, etc) time I use headerfont, the text is output correctly, but seems to be set to white (on a white background). Am I missing something here?

Cheers


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 09, 2012 8:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!
Cory Dee wrote:
Am I missing something here?
We never use MigraDoc this way. Maybe something goes wrong in the "Clone()" calls.

We would define Styles with the different colors and font styles. Then we'd just set the Style of the paragraphs.

See the file Styles.cs in the HelloMigraDoc sample for recommended usage.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 09, 2012 4:17 pm 
Offline

Joined: Wed Feb 08, 2012 6:36 pm
Posts: 8
Thanks for the idea, Thomas. I still seem to be having the same problem, though.

Here's the code now:

Code:
            //set the standard font
            var style = document.Styles["Normal"];
            style.Font.Name = "Arial";
            style.Font.Size = 10;
            style.Font.Color = Colors.Black;
            style.Font.Bold = false;

            //set the title font
            style = document.Styles["Heading1"];
            style.Font.Name = "Clarendon";
            style.Font.Size = 20;
            style.Font.Color = Color.Parse("0x43545E");
            style.Font.Bold = true;

            //set the heading font
            style = document.Styles["Heading2"];
            style.Font.Name = "Arial";
            style.Font.Size = 13;
            style.Font.Color = Color.Parse("0x43545E");
            style.Font.Bold = true;

            p = txtFr.AddParagraph("heading here");
            p.Style = "Heading2";
           
            p = txtFr.AddParagraph("normal text here");
            p.AddLineBreak();
            p.AddLineBreak();
            p.Style = "Normal";

            p = txtFr.AddParagraph("heading2");
            p.Style = "Heading2";


The "heading2" looks to be rendered (I can cut and paste it), but it appears to white text on white background.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 09, 2012 8:24 pm 
Offline

Joined: Wed Feb 08, 2012 6:36 pm
Posts: 8
This seems to be an issue with Color.Parse(). I've switched this:
style.Font.Color = Color.Parse("0x43545E");
For this:
style.Font.Color = Color.FromRgbColor((byte)255, Color.Parse("0x43545E"));

And now it works just fine! Weird.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 13, 2012 9:27 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Cory Dee wrote:
style.Font.Color = Color.Parse("0x43545E");

This should also work: style.Font.Color = Color.Parse("0xFF43545E");

Your text probably wasn't white, it was transparent. This makes a difference when you activate the transparency grid in Adobe Reader.
I should have checked the Color.Parse source code last week. :oops:

So your original code should work - but using styles is better when the document grows (and you can add own styles when needed).

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 42 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