Page 1 of 1

PDF export empty when exporting temporary invisible chart

Posted: Mon Feb 12, 2018 11:12 am
by 15681044
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

Re: PDF export empty when exporting temporary invisible chart

Posted: Thu Feb 15, 2018 10:32 am
by Christopher
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");
		}

Re: PDF export empty when exporting temporary invisible chart

Posted: Fri Feb 16, 2018 8:11 am
by 15681044
This works indeed.
Thank you very much!