Lazarus=4.3 64bit-Windows
FPC = 3.2.3 - 64Bit Windows
Target = Windows64
Ich habe ein TChart, welches ich nach PDF exportieren soll
Habe wie folgt
Code: Alles auswählen
function ExportChartToPDF(AChart: TChart; AFileName: String): Boolean;
var
Bitmap: TJpegImage;
PDFDoc: TPDFDocument;
Section: TPDFSection;
Page: TPDFPage;
ImgIndex: Integer;
b:boolean;
m:TMemoryStream;
begin
Result:=True;
b:=True;
Bitmap := TJpegImage.Create;
try
Bitmap.SetSize(AChart.Width, AChart.Height); //Grösse anpassen
AChart.PaintTo(Bitmap.Canvas, 0, 0); //Zeichne das Chart ins JPEG
m:=TMemoryStream.Create;
Bitmap.SaveToStream(m); //Wirf das Bitmap in einen Stream
m.Position:=0;
PDFDoc := TPDFDocument.Create(nil);
try
PDFDoc.StartDocument;
Section := PDFDoc.Sections.AddSection;
Page := TPDFPage.Create(PDFDoc);
Page.Orientation:=ppoLandscape;
Section.AddPage(Page);
ImgIndex := PDFDoc.Images.AddJPEGStream(m, Bitmap.Width, Bitmap.Height);
Page.DrawImage(10, 10, AChart.Width, AChart.Height, ImgIndex);
ShowMessage('Sections-Count='+PDFDoc.Sections.Count.ToString);
ShowMEssage('Page-Count='+PDFDoc.Sections[0].PageCount.ToString);
// 5. Save the PDF file
PDFDoc.SaveToFile(AFileName);
Except
On E:Exception Do b:=False;
end;
finally
m.Free;
PDFDoc.Free;
Bitmap.Free;
end;
Result:=Result And b;
end; Beim SaveTofile knallts mit EListError Invalid Page Index (=0)
Kenn mich mit PDF und dem ganzen Kram überhaupt nicht aus.
Wo sitzt der Fehler?