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
| procedure THtml2Pdf.Execute;
var
LFormatWidth, LWidth, LHeight, LI: Integer;
LPages: TList;
LPage: TMetafile;
LScale: Single;
LMarginX, LMarginY, LPointsWidth, LPointsHeight, LMarginBottom: Single;
PageText: string;
begin
//ForceJPEGCompression := 80;
LPointsWidth := DefaultPageWidth - Centimeters2Points(MarginLeft + MarginRight);
LFormatWidth := Points2Pixels(LPointsWidth);
LWidth := Viewer.FullDisplaySize(LFormatWidth).cx;
if ScaleToFit and (LWidth > LFormatWidth) and (LFormatWidth > 0) then
LScale := LFormatWidth / LWidth
else
LScale := 1;
LPointsHeight := (DefaultPageHeight - Centimeters2Points(MarginTop + MarginBottom)) / LScale;
LHeight := Points2Pixels(LPointsHeight);
LPages := Viewer.MakePagedMetaFiles(LWidth, LHeight);
LMarginX := Centimeters2Points(MarginLeft);
LMarginY := -Centimeters2Points(MarginTop);
LMarginBottom := Centimeters2Points(MarginBottom);
for LI := 0 to LPages.Count - 1 do
begin
AddPage;
LPage := TMetafile(LPages[LI]);
with Canvas do begin
GSave;
Rectangle(LMarginX,LMarginBottom,LPointsWidth,LPointsHeight);
Clip; // THtmlView may print out of the margins ;)
RenderMetaFile(LPage, LScale, LMarginX, LMarginY);
GRestore;
if DrawPageNumber then begin
if DrawPageNumberText='' then
PageText := 'Page %d/%d' else
PageText := DrawPageNumberText;
PageText := Format(PageText,[LI+1,LPages.Count]);
SetFont('Arial',9,[]);
SetRGBStrokeColor(clBlack);
TextOut(LMarginX+(LPointsWidth-TextWidth(PDFString(PageText)))/2,
LMarginBottom-9, PDFString(PageText));
end;
end;
LPage.SaveToFile('D:\Delphi\pdf\synPdf\export\'+'Page'+IntToStr(LI+1)+'.emf');
FreeAndNil(LPage);
end;
FreeAndNil(LPages);
end; |
Partager