1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| function Imprimer(const Annee: String; const Numero: Integer): Boolean;
// imprimer un Stream { TODO : Non testée }
var
NomFichier: String;
FromPage, ToPage, Page: Integer;
FirstPage: Boolean;
AStream: TMemoryStream;
Bitmap: TBitmap;
R: TRectF;
fpdfrun: TFPdf;
fpdfViewRun: TFPdfView;
Printer : TPrinter;
begin
Result := False;
// ... chargement du stream (pdf)
if AStream.Size > 0 then
begin
Printer:=TPrinter.Create;
fpdfrun := TFPdf.Create(nil);
fpdfViewRun := TFPdfView.Create(nil);
try
fpdfrun.FileName := NomFichier;
fpdfViewRun.Pdf := fpdfrun;
fpdfViewRun.Active := True;
FromPage := 1;
ToPage := fpdfrun.PageCount;
Printer.Title := NomFichier;
FirstPage := True;
Printer.BeginDoc;
try
for Page := FromPage to ToPage do
begin
if FirstPage then
FirstPage := False
else
Printer.NewPage;
fpdfViewRun.PageNumber := Page;
Bitmap := fpdfViewRun.RenderPage(0, 0, Printer.PageWidth,
Printer.PageHeight, ro0, [rePrinting]);
try
R := TRectF.Create(0, 0, Printer.PageWidth, Printer.PageHeight);
Printer.Canvas.DrawBitmap(Bitmap, R, R, 1.0, True);
finally
Bitmap.Free;
end;
end;
finally
Printer.EndDoc;
end;
finally
fpdfViewRun.Active := False;
FreeAndNil(fpdfViewRun);
FreeAndNil(fpdfrun);
FreeAndNil(Printer);
end;
Result := True;
end;
// fin d'impression, mise à jour historique ...
finally
AStream.Free;
end;
end; |
Partager