PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sun Jul 13, 2025 9:16 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Feb 10, 2008 3:09 am 
Offline

Joined: Sun Feb 10, 2008 3:00 am
Posts: 1
Hi,

I believe I've found a bug that causes text to disappear when drawn with DrawString and XBrushes.Black immediately after drawing a rounded rectangle with a XLinearGradientBrush.
It could be that the bug is more general than that, but this is how I bumped into it. I'm using Pdfsharp 1.0.898.

The code below should illustrate the problem (at least it does on my machine). Try removing the DrawRoundedRectangle and see what happens.

Code:
            PdfDocument doc = new PdfDocument();
            PdfPage page = doc.AddPage();
            XGraphics gfx = XGraphics.FromPdfPage(page);

            XRect rect = new XRect(10, 10, 100, 100);
            gfx.DrawRoundedRectangle(
                new XPen(XColors.Black, 3),
                new XLinearGradientBrush(rect, XColors.Red, XColors.Green, XLinearGradientMode.Vertical),
                rect,
                new XSize(5, 5));

            gfx.DrawString("Some text that disappears", new XFont("Arial", 20), XBrushes.Black,
                new XRect(200, 200, 200, 200), XStringFormat.TopLeft);

            doc.Save("HelloWorld.pdf");
            Process.Start("HelloWorld.pdf");


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jun 13, 2008 9:14 am 
Offline

Joined: Fri Jun 13, 2008 9:11 am
Posts: 1
I recently started using PDFSharp in a project where i need some graphics.

I seem to have the same problem with this Brush.

Did you find a solution??

Thanks,
Luc


Top
 Profile  
Reply with quote  
PostPosted: Sun Nov 10, 2013 4:58 am 
Offline

Joined: Sun Nov 10, 2013 4:48 am
Posts: 1
Hello, the text is disappearing only if it is over the XLinearGradientBrush and only if the text XBrush (foreground brush) is black.
So if you change the text brush to nearly black: new XSolidBrush(XColor.FromArgb(1,1,1)) then it works.


Top
 Profile  
Reply with quote  
PostPosted: Mon May 05, 2014 11:13 pm 
Offline

Joined: Mon May 05, 2014 11:06 pm
Posts: 1
You can also workaround by saving the transformation state before using the XLinearGradientBrush and then restoring it after.

Code:
PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);

XGraphicsState state = gfx.Save();
XRect rect = new XRect(10, 10, 100, 100);
gfx.DrawRoundedRectangle(
                new XPen(XColors.Black, 3),
                new XLinearGradientBrush(rect, XColors.Red, XColors.Green, XLinearGradientMode.Vertical),
                rect,
                new XSize(5, 5));
gfx.Restore(state);

gfx.DrawString("Some text that disappears", new XFont("Arial", 20), XBrushes.Black,
                new XRect(200, 200, 200, 200), XStringFormat.TopLeft);

doc.Save("HelloWorld.pdf");
Process.Start("HelloWorld.pdf");


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

All times are UTC


Who is online

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