You are not logged in.
Pages: 1
I have done it. If you send me email i'll send it to you.
It works but I have some problems with calculation of page size. Currently it's hard-coded. Also I don't know which method 1 or 2 is better in terms of SynPdf. If there is no difference I would stick with method 1 as this method not depend on current printer.
Thanks.
procedure TForm1.FormActivate(Sender: TObject);
var
i: Integer;
Pdf: TPdfDocument;
Pages: TList;
MyMetafile: TMetafile;
Gdi: TPdfDocumentGDI;
MFPrinter: TMetaFilePrinter;
begin
// 1. Using TPdfDocument and Viewer.MakePagedMetaFiles
Pdf := TPdfDocument.Create;
try
Pdf.DefaultPaperSize := psA4;
Pages := Viewer.MakePagedMetaFiles(Trunc(Pdf.DefaultPageWidth * 1.30), Trunc(Pdf.DefaultPageHeight * 1.30)); // Not very elegant...
for i := 0 to Pages.Count - 1 do
begin
Pdf.AddPage;
MyMetafile := TMetafile.Create;
with TMetafileCanvas.Create(MyMetafile, 0) do
try
Draw(51, 18, TMetafile(Pages[i])); // To center metafile on page create new metafile...
finally
Free;
end;
Pdf.Canvas.RenderMetaFile(MyMetafile);
TMetafile(Pages[i]).Free;
MyMetafile.Free;
end;
Pages.Free;
Pdf.SaveToFile('c:\temp\output.pdf');
finally
Pdf.Free;
end;
// 2. Using TPdfDocumentGDI
Gdi := TPdfDocumentGDI.Create;
try
Printer.Orientation := poPortrait;
MFPrinter := TMetaFilePrinter.Create(nil);
Viewer.PrintPreview(MFPrinter);
Gdi.DefaultPageWidth := Trunc(MFPrinter.PaperWidth / MFPrinter.PixelsPerInchX * PixelsPerInch); // This is not A4 but should be
Gdi.DefaultPageHeight := Trunc(MFPrinter.PaperHeight / MFPrinter.PixelsPerInchY * PixelsPerInch);
for i := 0 to MFPrinter.LastAvailablePage - 1 do
begin
Gdi.AddPage;
SetMapMode(Gdi.VCLCanvas.Handle, MM_ANISOTROPIC);
SetWindowExtEx(Gdi.VCLCanvas.Handle, MFPrinter.PaperWidth, MFPrinter.PaperHeight, nil);
SetViewportExtEx(Gdi.VCLCanvas.Handle, Trunc(Gdi.DefaultPageWidth * 2.86), Trunc(Gdi.DefaultPageHeight * 2.86), nil);
SetWindowOrgEx(Gdi.VCLCanvas.Handle, 0, 0, nil);
Gdi.VCLCanvas.Draw(-10, 0, MFPrinter.MetaFiles[i]);
end;
MFPrinter.Free;
Gdi.SaveToFile('c:\temp\gdioutput.pdf');
finally
Gdi.Free;
end;
end;
Can PDF Engine be used in companion with pbear's htmlViewer to produce PDF from HTML? Or maybe there is another way to do this?
Thanks.
Pages: 1