Problems in various export formats

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
moellenberg
Newbie
Newbie
Posts: 3
Joined: Fri Jan 14, 2022 12:00 am

Problems in various export formats

Post by moellenberg » Tue Mar 15, 2022 9:07 am

(History: We've been using "TeeChart for .NET v2", version 2.0.2652.22325, for more than a decade in a web application we built for one of our customers. This application has to generate and export charts in both PNG and PDF format. At the time, we couldn't quite figure out how to get the PDF export to do what we needed, so we used EPS instead and converted the EPS files to PDF with an external program. This worked well enough, i.e. both formats look almost exactly the same when embedded into a document.

Recently, our customer asked us to upgrade our application to .NET 5.0, so we purchased a new TeeChart Pro license and are currently trying to get our software to run in .NET 5.0. However, I've run into problems with the current TeeChart assembly, version 4.2022.2.11)

I've created a minimal console application to reproduce the problems we're facing:

Code: Select all

using System;
using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using System.Drawing;

namespace TeeChartFontTestNetWindows {
    internal class Program {
        private const string ImagePath = "../../../TestDotNet48";

        internal static void Main(string[] args) {
            // When using stuff from SixLabors in .NET 5.0, we must register fonts manually
            //ChartFont.FontCollection.Install(@"C:\windows\fonts\arial.ttf");
            //ChartFont.FontCollection.Install(@"C:\windows\fonts\consola.ttf");
            //ChartFont.FontCollection.Install(@"C:\windows\fonts\times.ttf");
            var chart = new TChart();
            chart.Header.Brush.Color = Color.Aqua;
            chart.Header.Text = "The header";
            chart.Header.Transparent = false;
            SetFont(chart.Header.Font, "Arial", 20, false, Color.BlueViolet);

            chart.Series.Add(new Steema.TeeChart.Styles.Bar());
            chart.Series[0].Add(123, "A bar", Color.Coral);
            chart.Series[0].Add(456, "In PDF, the font is wrong whereas the label box is sized correctly.", Color.Green);
            chart.Series[0].Add(321, "Another bar", Color.Blue);
            SetFont(chart.Series[0].Marks.Font, "Times New Roman", 18, true, Color.Red);

            chart.Legend.Alignment = LegendAlignments.Top;
            SetFont(chart.Legend.Font, "Consolas", 14, true, Color.DarkOliveGreen);

            try {
                SaveAsPng(chart);
                SaveAsPdf(chart);
                SaveAsEps(chart); // throws NotImplementedException in .NET 5.0 Console !?!
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }

        private static void SetFont(IChartFont font, string family, int size, bool bold, Color color) {
            font.Name = family;
            font.Size = size;
            font.Bold = bold;
            font.Color = color;
        }

        private static void SaveAsPng(TChart chart) {
            var output = chart.Export.Image.PNG;
            output.Height = 600;
            output.Width = 800;
            output.Save($"{ImagePath}.png");
        }

        private static void SaveAsPdf(TChart chart) {
            var output = chart.Export.Image.PDF;
            output.Height = 600;
            output.Width = 800;
            var document = output.Document();
            document.NewPage();
            output.Save($"{ImagePath}.pdf");
        }

        private static void SaveAsEps(TChart chart) {
            var output = chart.Export.Image.EPS;
            output.Height = 600;
            output.Width = 800;
            output.Save($"{ImagePath}_for_pdf.eps");
        }
    }
}
Technically, I could get the above program to run in three different configurations (I'm attaching the resulting image files with each configuration):
  1. Console Application with .NET 4.8
    ImagesNet48.zip
    (33.83 KiB) Downloaded 720 times
    This configuration works best, but has some problems, most of all with font sizes in PDF. The visible label borders show that, despite the string measurement is correct, the label texts are nevertheless too small. A similar problem was discussed in https://www.steema.com/support/viewtopi ... =4&t=17530

    BTW, I had to call chart.Export.Image.PDF.Document().NewPage() prior to chart.Export.Image.PDF.Save(), or else the resulting PDF document was unreadable, according to Adobe Reader (it reported "no pages in file").

    The EPS format seems to be broken. I tried to load the EPS file in Ghostview which reported "%%Pages: doesn't match number of %%Page:". When I convert the EPS file to PDF I see only the title and the chart legend, not the chart itself (i.e. no bars, no axes).
  2. Windows Application with .NET 5.0-windows
    ImagesNet50Windows.zip
    (31.18 KiB) Downloaded 707 times
    To configure this, I first created a console application, then applied the following changes to the .csproj file:

    Code: Select all

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net5.0-windows</TargetFramework>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
    
    This configuration does not use the libraries from SixLabors but uses the System.Drawing and System.Windows.Forms DLLs instead. It works second best, but shows the additional problem of not using the brush settings correctly even in the PNG format (see chart title).

    EPS also does not work here (same symptom as in configuration a) ).

    Since we're running solely in a Windows environment, configurations a) and b) would be all we need. Out of curiosity, I also tried a third configuration:
  3. Console Appliction with .NET 5.0
    ImagesNet50.zip
    (47.31 KiB) Downloaded 750 times
    This configuration works to a certain degree but not as I would expect. First of all, I had to register fonts manually (as discussed in https://www.steema.com/support/viewtopi ... =4&t=17529). And it still wouldn't generate a valid PDF file. Adobe Reader reports a lack of any page in the file and calling PDFDocument.NewPage() didn't do the trick this time.

    Also, EPS output does not work at all. When I tried, it threw a NotImplementedException at me. I suspect that the unstable DLLs from SixLabors are really just too immature at this point.
As a summary, I cannot generate the PDF charts I need with the current version of TeeChart either way, be it directly or indirectly through EPS. I hope that the problems described above can be fixed somehow. I'm aware that I may have just failed to set up things correctly. However, the sparse documentation (hardly any more comprehensive than a decade ago, as it seems) didn't quite help me, either.

Please let me know if you need any further information in order to help me get this to run. Thanks!

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Problems in various export formats

Post by Christopher » Wed Mar 16, 2022 9:26 am

moellenberg wrote:
Tue Mar 15, 2022 9:07 am
Please let me know if you need any further information in order to help me get this to run. Thanks!
Thank you for reporting these issues to us. We recently became aware of the PDF/EPS issue in .NET 5/6 Desktop, as reported in our issue tracking software with id=2510. I have added your report as a link to a comment on this issue, and have also increased its importance and severity. With any luck we will have a resolution to these issues in the near future.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Problems in various export formats

Post by Christopher » Wed Mar 16, 2022 5:32 pm

Hello,
moellenberg wrote:
Tue Mar 15, 2022 9:07 am
Please let me know if you need any further information in order to help me get this to run. Thanks!
I've run a slightly modified version of your example in .NET Framework 4.0 using v2.0.2586.24039, the only code change being in the SaveAsPdf method:

Code: Select all

    private static void SaveAsPdf(TChart chart)
    {
      Steema.TeeChart.Export.PDFFormat output = chart.Export.Image.PDF;
      output.Height = 600;
      output.Width = 800;
      //Steema.TeeChart.Export.PDFDocument document = output.Document();
      //document.NewPage();
      output.Save($"{ImageName}.pdf");
    }
I attach the results here:
TestDotNetv2.0.2586.24039.zip
(40.42 KiB) Downloaded 738 times
I notice that the font problem existed then in this version for PDF, although not for EPS (I've added a rendered png of it in the zip). Searching these forums, I now remember that this is a limitation our PDF export has with fonts, as we can see here. Could you please confirm that your v2 TeeChart also had this limitation (I expect it did)?

We've also found that these PDF/EPS issues have flown under the radar because they are partly a product of the obfuscation we apply to our assemblies and not because of major issues in our source-code. We will continue to look into this and hope to get a resolution soon.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

moellenberg
Newbie
Newbie
Posts: 3
Joined: Fri Jan 14, 2022 12:00 am

Re: Problems in various export formats

Post by moellenberg » Mon Mar 21, 2022 1:28 pm

Hi Christopher,

I just tested with version v2.0.2586.24039 and can confirm that it shows the same problem.

If I get it correctly the root cause is that you are not, and have never been, embedding the fonts into the PDF output. But is that really necessary? Wouldn't it suffice to put a reference to the fonts into the document? Anyway, I'd really like to understand this limitation because I think that it is a quite serious one and should be resolved. Unfortunately, putting a PNG image into a document is no option for us as we need scalable images which work equally well on screen and in print.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Problems in various export formats

Post by Christopher » Tue Mar 22, 2022 12:19 pm

Hello,
moellenberg wrote:
Mon Mar 21, 2022 1:28 pm
If I get it correctly the root cause is that you are not, and have never been, embedding the fonts into the PDF output.
Yes, I believe that is the case.
moellenberg wrote:
Mon Mar 21, 2022 1:28 pm
But is that really necessary? Wouldn't it suffice to put a reference to the fonts into the document?
I'm not sure, as it's been a while since we've revisited this theme. For certain what you suggest is possible in EPS, as here we can display the correct fonts if they are already installed on the system. We'll look at this again.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Problems in various export formats

Post by Christopher » Thu Apr 14, 2022 12:01 pm

Hello,
Christopher wrote:
Tue Mar 22, 2022 12:19 pm
I'm not sure, as it's been a while since we've revisited this theme. For certain what you suggest is possible in EPS, as here we can display the correct fonts if they are already installed on the system. We'll look at this again.
We believe we've fixed this issue (id=2510) in our latest NuGet (v.4.2022.4.14)—I attach a Visual Studio solution with three apps (.NET 6.0 Console, .NET 6.0 WinForm, .NET Framework 4.8 WinForm) which encapsulates the test code you passed us so you can test the issue yourself.
ExportProblemsNET_Fixed.zip
(16.61 KiB) Downloaded 684 times
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

moellenberg
Newbie
Newbie
Posts: 3
Joined: Fri Jan 14, 2022 12:00 am

Re: Problems in various export formats

Post by moellenberg » Wed Apr 20, 2022 1:43 pm

Hi Christopher,
I tested your latest NuGet package (briefly, more test to follow) and it seems to be ok now. I can still see differences between PNG and PDF exports - diagrams have different scaling - but that may be a different problem.

During my tests, another question came up, nevertheless:

When I look at the package in NuGet package manager, the description says: "TeeChart.NET Pro Charting Components offer full cross-platform support for .NET desktop, WPF and Universal Windows Platform (UWP), Javascript Library for ASP.NET, MVC, NET5.0, NET6.0 and NetCore 3."

Besides NET5.0 I also tried NetCore 3.1, but that doesn't work. I get a NuGet warning NU1701
Package "Steema.TeeChart.NET 4.2022.4.14" was restored using ".NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8" instead the project target framework ".NETCoreApp,Version=v3.1". This package may not be fully compatible with your project.
and the program does not compile (or it crashes at runtime). Do you still support .NET Core 3.1?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Problems in various export formats

Post by Christopher » Wed Apr 20, 2022 2:13 pm

Hello,
moellenberg wrote:
Wed Apr 20, 2022 1:43 pm
I tested your latest NuGet package (briefly, more test to follow) and it seems to be ok now.
Okay, good. Please let us know if you discover any further limitations with our PDF/EPS export formats.
moellenberg wrote:
Wed Apr 20, 2022 1:43 pm
Do you still support .NET Core 3.1?
We don't distribute assemblies for .NET Core 3.1, but we can certainly build some for you if you need them.

There is a mismatch though between what the NuGet package reports in Visual Studio:
Screenshot from 2022-04-20 16-06-21.png
Screenshot from 2022-04-20 16-06-21.png (23.53 KiB) Viewed 9916 times
And what our NuGet webpage reports:
Screenshot from 2022-04-20 16-06-45.png
Screenshot from 2022-04-20 16-06-45.png (101.83 KiB) Viewed 9916 times
Thank you for pointing this out to us, we'll update them both as soon as possible.
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply