Unplanned
Last Updated: 29 Jul 2026 13:01 by ADMIN
Giovanni Rojas
Created on: 29 Jul 2026 11:21
Category: PDFViewer
Type: Bug Report
1
PDF Viewer: Shading element is not rendered as expected
when having a shading type 3 element in the document, it is not rendered as expected in the Viewer.
1 comment
ADMIN
Didi
Posted on: 29 Jul 2026 13:01

Workaround:

Subscribe to the PageElementsLoaded
Get the page (e.Page, a RadFixedPage) and calls RecolorRadialShading(page.Content) to alter its content.
If an element is a Path whose Fill is a RadialGradient (PDF shading type 3), it replaces the fill with solid white (new RgbColor(255, 255, 255)) — effectively neutralizing/hiding the radial shading.

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        RadFixedDocument document = ImportBackBaseDocument();

        this.pdfViewer.PageElementsLoaded += OnPageElementsLoaded;
        this.pdfViewer.Source = new FixedDocumentSource(document);
    }

    private void OnPageElementsLoaded(object sender, PageElementsLoadedEventArgs e)
    {
        RadFixedPage page = e.Page;
        if (page is not null)
        {
            RecolorRadialShading(page.Content);
        }
    }

    // Walks the page content, recursing into MarkedContent containers, and
    // recolors any Path whose Fill is a RadialGradient (PDF shading type 3).
    private static void RecolorRadialShading(ContentElementCollection content)
    {
        if (content is null)
        {
            return;
        }

        foreach (var element in content)
        {
            switch (element)
            {
                case GraphicsPath path when path.Fill is RadialGradient:
                    path.Fill = new RgbColor(255, 255, 255);
                    break;

                case MarkedContent marked:
                    RecolorRadialShading(marked.Content);
                    break;
            }
        }
    }

    private static RadFixedDocument ImportBackBaseDocument()
    {
        Assembly assembly = typeof(MainPage).Assembly;
        string fileName = assembly.GetManifestResourceNames()
            .FirstOrDefault(n => n.Contains("yourpdf_file.pdf"));

        using Stream stream = assembly.GetManifestResourceStream(fileName);
        using MemoryStream memoryStream = new MemoryStream();
        stream.CopyTo(memoryStream);

        PdfFormatProvider formatProvider = new PdfFormatProvider();
        return formatProvider.Import(memoryStream.ToArray(), TimeSpan.FromMilliseconds(200));
    }
}

Regards,
Didi
Progress Telerik