Problems in various export formats
Posted: 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:
Technically, I could get the above program to run in three different configurations (I'm attaching the resulting image files with each configuration):
Please let me know if you need any further information in order to help me get this to run. Thanks!
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");
}
}
}
- Console Application with .NET 4.8 https://www.steema.com/support/viewtopi ... =4&t=17530
BTW, I had to callchart.Export.Image.PDF.Document().NewPage()
prior tochart.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).
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 - Windows Application with .NET 5.0-windows
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).Code: Select all
<PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>net5.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup>
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:
To configure this, I first created a console application, then applied the following changes to the .csproj file: - Console Appliction with .NET 5.0 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.
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
Please let me know if you need any further information in order to help me get this to run. Thanks!