PDF export empty when exporting temporary invisible chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
OMP
Newbie
Newbie
Posts: 11
Joined: Thu Jun 01, 2017 12:00 am

PDF export empty when exporting temporary invisible chart

Post by OMP » Mon Feb 12, 2018 11:12 am

Hi,

I want to create a temporary chart and export it immediately to PDF, without showing it to the user.
I use following code to do this:

Code: Select all

Steema.TeeChart.TChart tChart2 = new Steema.TeeChart.TChart();
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart2.Chart);
line1.Add(0, 0, "Category 1");
line1.Add(1, 20, "Category 2");
line1.Add(2, 30, "Category 3");

// Steema.TeeChart.Export.PNGFormat pngFormat = tChart2.Export.Image.PNG;
// pngFormat.Width = 1024;
// pngFormat.Height = 576;
// pngFormat.Save("test.png");

Steema.TeeChart.Export.PDFFormat pdfFormat = tChart2.Export.Image.PDF;
pdfFormat.Width = 1024;
pdfFormat.Height = 576;
pdfFormat.Save("test.pdf");
Unfortunately, the resulting PDF file shows just an empty page without chart.
However, when I export the chart to PNG, the resulting PNG file correctly shows the chart as it should be.
Also, when first exporting the chart to PNG and then to PDF right after that (by uncommenting the code above), the resulting PDF also correctly shows the chart as it should be.

Did I forget some kind of initialization step before exporting the chart to PDF, which is automatically done when exporting the chart to PNG first?

Best regards,
Steven

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

Re: PDF export empty when exporting temporary invisible chart

Post by Christopher » Thu Feb 15, 2018 10:32 am

Hello Steven,

You will be able to get this to work by adding a call to the Draw() method, e.g.

Code: Select all

		private void button1_Click(object sender, EventArgs e)
		{
			Steema.TeeChart.TChart tChart2 = new Steema.TeeChart.TChart();
			Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart2.Chart);
			line1.Add(0, 0, "Category 1");
			line1.Add(1, 20, "Category 2");
			line1.Add(2, 30, "Category 3");

			tChart2.Draw();

			// Steema.TeeChart.Export.PNGFormat pngFormat = tChart2.Export.Image.PNG;
			// pngFormat.Width = 1024;
			// pngFormat.Height = 576;
			// pngFormat.Save("test.png");

			Steema.TeeChart.Export.PDFFormat pdfFormat = tChart2.Export.Image.PDF;
			pdfFormat.Width = 1024;
			pdfFormat.Height = 576;
			pdfFormat.Save(@"D:\tmp\test.pdf");
		}
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

OMP
Newbie
Newbie
Posts: 11
Joined: Thu Jun 01, 2017 12:00 am

Re: PDF export empty when exporting temporary invisible chart

Post by OMP » Fri Feb 16, 2018 8:11 am

This works indeed.
Thank you very much!

Post Reply