SVG pictures broken in pdf

1 Answer 38 Views
PictureBox
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Benedikt asked on 14 Dec 2021, 07:45 AM

Hi guys,

I have a strange problem with svg pictures in my project.
Displayed in a viewer or printed everything is rendered as it should be (left side). But if saved to pdf everything is a bit off. Not where it should be anymore.
I have added the pdf made with save as pdf, and one where I printed it to a PDF printer.
I use a picturebox. A field from a sql request contains the link.
No special settings I think.
Is there some hidden setting I have to set? 
I also added the svg maybe there is something wrong there.

 

Greetings Benedikt

Dimitar
Telerik team
commented on 16 Dec 2021, 01:49 PM

Thank you for the attached files, I was able to reproduce the issue with the provided SVG. It seems that there is already a bug report about a similar issue - SVG image is incorrectly rendered in PDF-export when the PictureBox's Sizing property is set to Normal, Stretch or Centered, however, I can confirm that the issue is also present when using ScaleProportional. I suggest casting your vote on this bug report and you may also leave a comment that the issue is present with ScaleProportional too.

Currently, the only workaround is to disable the usage of the vector-based graphic primitives for SVG images by setting the UseSvgVectorRendering runtime setting to False. For more information, please see the PDF Device Information Settings article.

This setting can be enabled per report so that SVGs that work still render with the vector graphics - Enable per-report allowed export formats configuration.

Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 16 Dec 2021, 02:36 PM

Hi Dimitar,

thanks for the hint. Setting UseSvgVectorRendering to false seems to work. 
The problem is I can't find the right place for iot in the final Report.
I have a Subreport in a Report that is part of a ReportBook. I have set this setting in both, the subreport and Report and if I save them to pdf it takes affect.
But if I save the ReportBook in the ReportViewer, it still is like before.
Here is a snippet of the creation of the Reportbook as an InstanceReportSource for my ReportViewer.

            this.FepasAnsichtViewer.ReportSource = clsDaten.CreateFepaReportBook(Los);
       
            RenderingSettings pdfSettings = new RenderingSettings() { Name = "PDF", Visible = true };
            pdfSettings.Parameters.Add(new Parameter() { Name = "UseSvgVectorRendering", Value = false });
            this.RuntimeSettings.Add(pdfSettings);

 public static InstanceReportSource CreateFepaReportBook(clsLosForView los)
        {
            ReportBook reportBook = new ReportBook();
            reportBook.DocumentName = "Fepas_" + los.PROIDENT + "_" + los.Typ + "_" + los.Losnummer;

            DataTable dtFepasListenReihenfolge = GibFepasListenReihenfolge(los.Typ);

            DataTable dtKategorieblatt = GibFepasKategorieblatt(los.PROIDENT, los.ID);

            bool Sandwichplatten = (bool)dtKategorieblatt.Rows[0]["Sandwichplatten"];
            int FräslistenArt = (int)dtKategorieblatt.Rows[0]["FräslistenArt"];

            bool HatPlatten = (bool)dtKategorieblatt.Rows[0]["HatPlatten"];
            bool HatTüren = (bool)dtKategorieblatt.Rows[0]["HatTüren"];
            bool HatProfile = (bool)dtKategorieblatt.Rows[0]["HatProfile"];
            bool HatStabis = (bool)dtKategorieblatt.Rows[0]["HatStabis"];
            bool HatMagazin = (bool)dtKategorieblatt.Rows[0]["HatMagazin"];
            bool HatKanban = (bool)dtKategorieblatt.Rows[0]["HatKanban"];
            bool HatSchmaleTeile = (bool)dtKategorieblatt.Rows[0]["HatSchmaleTeile"];
            bool HatRahmen = (bool)dtKategorieblatt.Rows[0]["HatRahmen"];
            bool HatFüllungen = (bool)dtKategorieblatt.Rows[0]["HatFüllungen"];

            foreach (DataRow drListe in dtFepasListenReihenfolge.Rows)
            {
                string Bezeichnung = (string)drListe["Bezeichnung"];
                string Parameter = drListe["Parameter"] == DBNull.Value ? null : (string)drListe["Parameter"];
                string AusnahmeKommtNurWenn = drListe["AusnahmeKommtNurWenn"] == DBNull.Value ? null : (string)drListe["AusnahmeKommtNurWenn"];
                bool AusnahmeKommtNurWennBool = true;
                if (AusnahmeKommtNurWenn != null)
                {
                    if (AusnahmeKommtNurWenn == "HatPlatten" && !HatPlatten)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatTüren" && !HatTüren)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatProfile" && !HatProfile)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatStabis" && !HatStabis)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatMagazin" && !HatMagazin)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatKanban" && !HatKanban)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatSchmaleTeile" && !HatSchmaleTeile)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatRahmen" && !HatRahmen)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                    else if (AusnahmeKommtNurWenn == "HatFüllungen" && !HatFüllungen)
                    {
                        AusnahmeKommtNurWennBool = false;
                    }
                }

                if (Bezeichnung == "Einlagen" && HatFüllungen)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Fräßliste" && ((FräslistenArt == 1 && HatTüren) | (FräslistenArt != 1 && HatPlatten)))
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Kanban" && HatKanban)
                {
                    foreach (DataRow drKanban in GibFepasKanbanlisteListen(los.PROIDENT, los.ID).Rows)
                    {
                        string PARTDELIVERYADDRESS = (string)drKanban["PARTDELIVERYADDRESS"];

                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, PARTDELIVERYADDRESS, Sandwichplatten, FräslistenArt);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                }
                else if (Bezeichnung == "Kanten" && HatPlatten)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Klebeliste" && HatFüllungen)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Ladeliste")
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Ladeliste(los.PROIDENT, los.ID);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Mappenkennung" && AusnahmeKommtNurWennBool)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Mappenkennung(los.PROIDENT, los.ID);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Montageliste" && HatMagazin)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "MontageSammelliste" && HatMagazin)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Plattenliste" && HatPlatten)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Profile" && HatProfile)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "ProfileTekna" && HatProfile)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Rahmenprofile" && HatRahmen)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Sitzbank" && AusnahmeKommtNurWennBool)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Stabibohrliste" && HatStabis)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "PlattenlisteSchmaleTeile" && HatSchmaleTeile)
                {
                    InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                    instanceReportSourceSub.ReportDocument = new Headerblatt(los.PROIDENT, los.ID, Bezeichnung, Sandwichplatten, FräslistenArt);
                    reportBook.ReportSources.Add(instanceReportSourceSub);
                }
                else if (Bezeichnung == "Kategorieblatt")
                {
                    if (Parameter == "" | Parameter == "EM")
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if (Parameter == "Kanban" && HatKanban)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if ((Parameter == "BAZ" | Parameter == "Säge" | Parameter == "KantenBAZ" | Parameter == "TürenBAZKantenBAZ" | Parameter == "BAZKantenBAZ") && HatPlatten)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if ((Parameter == "Einlagenzuschnitt" | Parameter == "Kleben") && HatFüllungen)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if (Parameter == "Rahmen" && HatRahmen)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if (Parameter == "Alu" && HatProfile)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                    else if (Parameter == "TürenBAZ" && HatTüren)
                    {
                        InstanceReportSource instanceReportSourceSub = new InstanceReportSource();
                        instanceReportSourceSub.ReportDocument = new Kategorieblatt(los.PROIDENT, los.ID, Parameter);
                        reportBook.ReportSources.Add(instanceReportSourceSub);
                    }
                }
            }

            InstanceReportSource instanceReportSource = new InstanceReportSource();
            instanceReportSource.ReportDocument = reportBook;

            return instanceReportSource;
        }

Todor
Telerik team
commented on 21 Dec 2021, 11:11 AM

I would recommend using the per-report allowed export formats configuration. Please, note that in the case of a Report Book document, the settings of the first Report in the book get respected. That said, you need to modify the logic so that it adds the settings to the first report definition that gets added to the book. The programmatic approach is demonstrated with sample code in the article section Set the RuntimeSettings through code.

The other approach would be to configure the PDF Device Information settings in the configuration file of the project where you host the code that renders the report book. For more details, check the article extensions Element.

 

Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 18 Jan 2022, 08:35 AM

Hi Todor,

It seems that the approach with

            RenderingSettings pdfSettings = new RenderingSettings() { Name = "PDF", Visible = true };
            pdfSettings.Parameters.Add(new Parameter() { Name = "UseSvgVectorRendering", Value = false });
            RuntimeSettings.Add(pdfSettings);

solves the SVGs when exporting to PDF in the frontend.

 

But with the RenderReport Function from code behind it doesnt.
                    ReportProcessor reportProcessor = new ReportProcessor();
                    Hashtable deviceInfo = new Hashtable();
                    InstanceReportSource reportSource = clsDaten.CreateFepaReportBook(this);

                    RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, deviceInfo);

Do you have a solution for this aswell?
Dimitar
Telerik team
commented on 20 Jan 2022, 09:41 AM

Yes, you may add the setting to the deviceInfo object. For example:

deviceInfo["UseSvgVectorRendering"] = false;

Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
commented on 21 Jan 2022, 08:06 AM

Works perfect, thank you :)

1 Answer, 1 is accepted

Sort by
0
Accepted
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
answered on 23 Dec 2021, 08:35 AM

I have now set recommended setting to every report used in the reportbook cause the order can vary.

Now it renders correctly.

 

Thanks Todor.

 

Greetings and happy christmas

Benedikt

Tags
PictureBox
Asked by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Benedikt
Top achievements
Rank 3
Iron
Iron
Iron
Share this question
or