PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 2:03 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Nov 02, 2023 11:34 pm 
Offline

Joined: Fri Jun 02, 2023 10:41 pm
Posts: 2
Hello guys, thank you for an awesome PDF lib, really appreciated.

As for this bugreport:
The following code produces a solid red rectangle, without gradient to transparent as I hoped for.
The code can be run as console app (copy paste console app), .net6.0, pdfsharp prev 4.
Checked in chrome, edge and sumatraPdf.
Am I missing something?
Code:
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System.IO;

public static void DrawGradientRectangle(string filePath)
{
    using (PdfDocument document = new PdfDocument())
    {
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XRect rect = new XRect(50, 50, 250, 100); // x, y, width, height

        // Create a red to transparent gradient brush
        XLinearGradientBrush brush = new XLinearGradientBrush(
            rect,
            XColor.FromArgb(255, 255, 0, 0), // Solid Red
            XColor.FromArgb(0, 255, 0, 0),   // Transparent Red
            XLinearGradientMode.Horizontal
        );

        // Draw the rectangle with the gradient brush
        gfx.DrawRectangle(brush, rect);

        // Save the document
        document.Save(filePath);
    }
}

// Call the function and provide the path to save the PDF
DrawGradientRectangle("GradientRectangle.pdf");



Top
 Profile  
Reply with quote  
PostPosted: Tue Nov 07, 2023 1:33 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
pablovlc wrote:
The following code produces a solid red rectangle, without gradient to transparent as I hoped for.
Are you using the WPF build?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 10, 2023 5:11 pm 
Offline

Joined: Fri Jun 02, 2023 10:41 pm
Posts: 2
Thank you for looking into this issue.

Version used: Dotnet 6 core preview 4 on windows.
I upgraded to Version 6 stable release, again core. The result is the same.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 13, 2023 10:53 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
As far as I can tell, this is not a bug.

XColor is the interface and it supports transparency.
Gradient fills in PDF seem to work with solid colors only, so transparency gets lost at this stage.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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: Bing [Bot] and 384 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