PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Mar 19, 2024 2:20 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Jun 19, 2020 8:17 pm 
Offline

Joined: Fri Jun 19, 2020 7:55 pm
Posts: 1
I need to import PDF files inside a PDF page I'm creating using PDFSharp 1.50.5147 but changing their color and transparency. I already achieved the color change by converting the PDF file to EPS, applying some GhostScript and convert it back to PDF.

My problem now is how to alter the opacity for the XImage (created from the PDF file I just mentioned), from another post in this forum they mentioned changing the RealizeNonStrokeTransparency() which had a hardcoded opacity of 1, so, I downloaded the source code and compiled a new PDFSharp DLL changing the Realize() method in XGraphicsPdfRenderer.cs so I can alter the image opacity:

Code:
/// <summary>
/// Makes the specified image to the current graphics object.
/// </summary>
string Realize(XImage image, double transparency)
{
    BeginPage();
    BeginGraphicMode();
    RealizeTransform();

     // The transparency set for a brush also applies to images.
     _gfxState.RealizeNonStrokeTransparency(transparency, _colorMode);

     XForm form = image as XForm;
     return form != null ? GetFormName(form) : GetImageName(image);
}


This works great as the XImage I'm inserting has it's opacity altered. This is the PDF file I'm loading as an XImage and this is the resulting PDF (I'm also attaching both files). You can see the fill has changed its opacity (I use a value of 0.5) BUT the stroke didn't change its opacity at all! I tried changing the stroke color transparency too using this code:

Code:
/// <summary>
/// Makes the specified image to the current graphics object.
/// </summary>
string Realize(XImage image, double transparency)
{
    BeginPage();
    BeginGraphicMode();
    RealizeTransform();

     // The transparency set for a brush also applies to images.
     _gfxState.RealizeNonStrokeTransparency(transparency, _colorMode);
     _gfxState.RealizeStrokeTransparency(transparency);

     XForm form = image as XForm;
     return form != null ? GetFormName(form) : GetImageName(image);
}


And adding the RealizeStrokeTransparency() to PdfGraphicsState.cs:

Code:
internal void RealizeStrokeTransparency(double transparency)
{
      _realizedStrokeColor.A = transparency;
}


But it didn't affect the end result at all, obviously, I'm not understanding how the rendering process works here. Any guidance would be greatly appreciated!

Thank you very much!

Andres


Attachments:
OpacityIssue.zip [19.47 KiB]
Downloaded 379 times
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

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