PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jun 29, 2024 11:51 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
 Post subject: Custom Font Color
PostPosted: Mon Mar 21, 2011 2:00 am 
Offline

Joined: Mon Mar 21, 2011 1:49 am
Posts: 3
Hi,

I have written a fairly simple C# windows app that draws a background image then text on top of it.
I can not seem to set the font color to a "custom" color (RGB or CMYK) but the predefined colors work.
The custom colors appear black. I hope I'm missing something simple.
Any help is appreciated.

Thank you,
Joe

Code:
            PdfDocument document = new PdfDocument();

            // Create a new page
            PdfPage page = document.AddPage();
            page.Size = PageSize.Letter;
            page.Orientation = PageOrientation.Portrait;
           
            XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards);

            // Draw background
            gfx.DrawImage(XImage.FromFile("Background.pdf"), 0, 0);

            // Write on top of background with known colors
            gfx.DrawString("Name", new XFont("Garamond", 12, XFontStyle.Regular), XBrushes.Firebrick, 100, 670, XStringFormats.TopLeft);
            gfx.DrawString("Title", new XFont("Garamond", 10, XFontStyle.Italic), XBrushes.DodgerBlue, 100, 685, XStringFormats.TopLeft);
           
            // Write on top of background with custom colors
            // DOES NOT WORK, COMES OUT BLACK!!!!!!

            gfx.DrawString("Phone", new XFont("Garamond", 12, XFontStyle.Regular), new XSolidBrush(XColor.FromCmyk(62, 28, 2, 3)), 100, 700, XStringFormats.TopLeft);
            gfx.DrawString("Email", new XFont("Garamond", 10, XFontStyle.Regular), new XSolidBrush(XColor.FromCmyk(5, 95, 39, 16)), 100, 715, XStringFormats.TopLeft);

            // Save the document...
            document.Save("BackgroundWithText.pdf");


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Font Color
PostPosted: Mon Mar 21, 2011 9:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!

Please note that CMYK uses floating point numbers for the colour components.
Values >= 1 mean full saturation. So all colours you specify are black!

See also here:
http://www.pdfsharp.net/wiki/ColorsCMYK ... hx?HL=cmyk

You use CMYK colours, but you don't set the PDF file to CMYK mode. This should not make a big difference.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Font Color
PostPosted: Mon Mar 21, 2011 5:50 pm 
Offline

Joined: Mon Mar 21, 2011 1:49 am
Posts: 3
Hi Thomas,

Thanks for the quick reply. I won't be able to test it out untill tonight but it leads to my next question. Do I enter the CMKY values as a percentage of 255 or of 100. In other words, the values I tried (62, 28, 2, 3) were given to me from someone that uses photo shop. Should I enter 0.62, 0.28, 0.02, 0.03 or 62/255, 28/255 etc.? I guess I could just try each case myself but if you know that would be great.

Thanks again,
Joe


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Font Color
PostPosted: Tue Mar 22, 2011 8:37 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
slowjoe wrote:
Should I enter 0.62, 0.28, 0.02, 0.03 or 62/255, 28/255 etc.?

I'd go for 0.62, 0.28, 0.02, 0.03 (that's what the average photo shop user will expect to see).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom Font Color
PostPosted: Tue Mar 22, 2011 2:25 pm 
Offline

Joined: Mon Mar 21, 2011 1:49 am
Posts: 3
Hi Thomas,

That was what I needed - the colors look right.

Thank you very much,
Joe


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: No registered users and 53 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