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