I've been looking if i could create a export to pdf without the need for a external dll and i 've found SynPDf. With the change in the following methods (and the addition of SynPDF to the uses) you can create PDF's with it:
- Code: Select all
procedure TPrintPreview.SaveAsPDF(const FileName: String);
function PaperTypeToPDFPaperSize(PaperType: TPaperType): TPDFPaperSize;
begin
case PaperType of
pLetter : Result := psLetter;
pLegal : Result := psLegal;
pA3 : Result := psA3;
pA4 : Result := psA4;
pA5 : Result := psA5;
else
Result := psUserDefined; // Default to custom
end;
end;
var
PaegNo: Integer;
pdf: TPdfDocument;
begin
pdf := TPdfDocument.Create;
try
ChangeState(psSavingPDF);
try
if FileExists(FileName) and not IsFileWritable(FileName) then begin
raise Exception.Create(Format(_('Unable to write to file %s. Is the file opened by another application?'), [FileName]));
end;
pdf.NewDoc;
try
pdf.Info.Author := FPDFDocumentInfo.Author;
pdf.Info.CreationDate := Date;
pdf.Info.Creator := FPDFDocumentInfo.Creator;
//pdf.Info.Keywords
//pdf.Info.ModDate
pdf.Info.Subject := FPDFDocumentInfo.Subject;
pdf.Info.Title := FPDFDocumentInfo.Title;
//FPDFDocumentInfo.Producer
pdf.DefaultPaperSize := PaperTypeToPDFPaperSize( PaperType );
// if pdf.DefaultPaperSize = psUserDefined then begin
pdf.DefaultPageWidth := ConvertX(PaperWidth, Units, mmPoints);
pdf.DefaultPageHeight := ConvertY(PaperHeight, Units, mmPoints);
// end;
for PaegNo := 1 to TotalPages do begin
pdf.AddPage;
pdf.Canvas.RenderMetaFile(Pages[PaegNo]);
end;
finally
pdf.SaveToFile(FileName);
end;
finally
ChangeState(psReady);
end;
finally
pdf.Free;
end;
end;
function TPrintPreview.CanSaveAsPDF: Boolean;
begin
Result := true;
end;
You can find the Synopse PDF libray at: http://www.synopse.info