wPDF comrades:
I have a simple graphic on a screen that was drawn to a TMetafile. I have a popup menu that currently allows me to send the metafile graphic to the printer. Here's the code:
procedure TLensForm.FormPrint(aPalette: TGKSPalette; MaxIndex: Integer);var i, Segs, Iz: Integer; Segns: array [0..GCMaxSegments - 1] of Integer; Mtrx: GMatr;begin try Printer.Orientation := poLandscape; Printer.BeginDoc; SetPrinterDcTransform; SetPalette(aPalette, MaxIndex); DrawMetafile := TMetafile.Create; DrawCanvas := TMetafileCanvas.Create(DrawMetafile, 0); Iz := LensId; Segs := SegNamesToInts (Iz, Segns); if Segs >= MinSegments then begin for i := 0 to NSegments - 1 do begin if Segns[i] > 0 then begin EvaluateMatrix (GetSegRecord(i)^.DX, GetSegRecord(i)^.DY, GetSegRecord(i)^.SclFctr, GetSegRecord(i)^.SclFctr, Mtrx); SetPrimitiveTransform(Mtrx); RetrieveSegment (Segns[i]); end; end; end; finally DrawCanvas.Free; DrawCanvas := nil; Printer.Canvas.Draw(0,0,DrawMetafile); DrawMetafile.Free; DrawMetafile := nil; SetPalette(clScreenPalette, GCMaxColorIndex); SetDcTransform; Printer.EndDoc; Printer.Orientation := poPortrait; end;end;
DrawCanvas is a component of an ancestor of TLensForm and the middle section of the code with the EvaluateMatrix draws the picture. When I send this to the printer I get beautiful resolution, much better than I see on the screen.
Here's the code I've written to get a PDF file
procedure TLensForm.FormPDF(aPalette: TGKSPalette; MaxIndex: Integer);
{
Purpose: Output a graphics file
Author: N. S. Clerman, June 2003 (from FormClipboard)
}
var
i, Segs, Iz, res: Integer;
Segns: array [0..GCMaxSegments - 1] of Integer;
Mtrx: GMatr;
begin
try
SetPalette(aPalette, MaxIndex);
DrawMetafile := TMetafile.Create;
DrawMetafile.Enhanced := TRUE;
{DrawCanvas is a component of TLensForm; RetrieveSegemnt below actually puts
the segment on the canvas}
DrawCanvas := TMetafileCanvas.Create(DrawMetafile, 0);
DrawCanvas.Font.Color := clBlack;
DrawCanvas.Pen.Color := clBlack;
{Retrieve the segments from the GKS system}
Iz := LensId;
Segs := SegNamesToInts (Iz, Segns);
if Segs >= MinSegments then
begin
for i := 0 to NSegments - 1 do
begin
if Segns[i] > 0 then
begin
EvaluateMatrix (GetSegRecord(i)^.DX, GetSegRecord(i)^.DY,
GetSegRecord(i)^.SclFctr,
GetSegRecord(i)^.SclFctr, Mtrx);
SetPrimitiveTransform(Mtrx);
RetrieveSegment (Segns[i]);
end;
end;
end;
finally
DrawCanvas.Free;
DrawCanvas := nil;
WPPDFPrinter1.Filename := 'OpconPic.pdf';
{res := Screen.PixelsPerInch;}
WPPDFPrinter1.BeginDoc;
try
{WPPDFPrinter1.StartPage(Round(8.5 * res), Round(10 * res), 5 * res, 5 * res, 0);
WPPDFPrinter1.Canvas.Draw(0,0,DrawMetafile);
WPPDFPrinter1.EndPage;}
WPPDFPrinter1.DrawMetafileEx(0,0,0,0,DrawMetafile.Handle,0,0);
finally
WPPDFPrinter1.EndDoc;
end;
DrawMetafile.Free;
DrawMetafile := nil;
Refresh;
end;
end;
Alles anzeigen
This gives me a file that when printed using Acrobat reader has far inferior resolution; the picture looks as it does on the screen. I've tried several different techniques, but none work. Is there any way I can achieve the same resolution in PDF that I'm getting with the direct Printer.Canvas.Draw(0, 0, DrawMetafile)?