PDF Export Problems
Posted: Mon Apr 18, 2016 2:45 am
I have created a simple FMX program to demonstrate some problems with the PDF export facility in the latest version of TChart Pro. The first figure is a screen capture of my program. The second figure is a screen capture of the resulting PDF. (The graph axis ranges and tick marks have been set manually rather than automatically by TChart.)
My issues with the PDF are listed below:
(1) The font family is not respected but instead a default font is used in the PDF. This is a major problem when using TChart for commercial software development. A fully functional PDF export would respect all the chart properties.
(2) The left axis title is wrongly positioned in the PDF. It clashes with the left axis labels. (If the left axis is created automatically by TChart, rather than manually as here, the clashing is not as bad but still occurs. The clashing is also worse for larger font sizes. Note that the problem is only with the left axis, the bottom axis is fine.)
(3) With a large axis label font, the rightmost label on the bottom axis has been cropped.
(4) Trying to convert the PDF to JPG so I could show it as an
My issues with the PDF are listed below:
(1) The font family is not respected but instead a default font is used in the PDF. This is a major problem when using TChart for commercial software development. A fully functional PDF export would respect all the chart properties.
(2) The left axis title is wrongly positioned in the PDF. It clashes with the left axis labels. (If the left axis is created automatically by TChart, rather than manually as here, the clashing is not as bad but still occurs. The clashing is also worse for larger font sizes. Note that the problem is only with the left axis, the bottom axis is fine.)
(3) With a large axis label font, the rightmost label on the bottom axis has been cropped.
(4) Trying to convert the PDF to JPG so I could show it as an
Code: Select all
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls, FMXTee.Engine, FMXTee.Procs,
FMXTee.Chart, FMXTee.Series, System.UIConsts, FMX.TMSToolBar,
FMXTee.Canvas.PDF, FMXTee.Canvas;
type
TForm1 = class(TForm)
Chart1: TChart;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
c: TPDFCanvas;
MyRect: TRectF;
begin
c := TPDFCanvas.Create;
try
MyRect := TRectF.Create(0, 0, Chart1.Width, Chart1.Height);
TPDFExportFormat.Draw(c, Chart1, MyRect);
with TSaveDialog.Create(nil) do
try
Filter := 'Adobe PDF files (*.pdf)|*.pdf';
DefaultExt := 'pdf';
if Execute then
c.SaveToFile(Filename);
finally
Free;
end;
finally
c.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
X, Y: Double;
begin
with Chart1 do
begin
// Set some chart properties
View3D := False;
BevelWidth := 0;
Shadow.Visible := False;
BottomAxis.Title.Text := 'Bottom axis title';
LeftAxis.Title.Text := 'Left axis title';
// SET BOTTOM AXIS RANGE AND TICK MARKS
Axes.Bottom.SetMinMax(0.5, 2.5);
for I := 0 to 4 do
Axes.Bottom.Items.Add(I + 0.5, FloatToStr(I + 0.5));
// SET LEFT AXIS RANGE AND TICK MARKS
Axes.Left.SetMinMax(1, 4);
for I := 0 to 3 do
Axes.Left.Items.Add(I + 1, IntToStr(I + 1));
Title.Text[0] := 'Chart Title';
Title.Font.Color := claBlue;
Title.Font.Name := 'Courier';
Title.Font.Style := [TFontStyle.fsBold];
Title.Font.Size := 36;
Subtitle.Text[0] := 'Chart Subtitle';
Subtitle.Font.Color := claRed;
Subtitle.Font.Name := 'Arial';
AddSeries(TLineSeries.Create(Self));
// WITH BIGGER FONTS, CLASHING IS WORSE
LeftAxis.Title.Font.Size := 24;
LeftAxis.LabelsFont.Size := 18;
BottomAxis.Title.Font.Size := 24;
BottomAxis.LabelsFont.Size := 18;
Legend.LegendStyle := lsSeries;
Legend.Alignment := laTop;
Series[0].LegendTitle := 'Series Legend Title';
// Create series data
for I := 0 to 20 do
begin
X := 0.5 + I * 0.1;
Y := 3 / X;
Series[0].AddXY(X, Y);
end;
end;
end;
end.