By now we created a metafile with screen resolution to let WPRichEdit
print graphics and text. The size was okay till then but now we wanted
to switch to a higher resolution to get a better granularity.
The displayed width and height which were displayed in the Acrobat reader
are okay (DinA4) but WPTools seems to shrink the output. That means I got a white paper (DinA4) and the text itself is shrinked to the top left corner
Code used for 96 dpi printing (Screen resolution):
Code
// Get screen-resolution ScreenDpi:=Screen.PixelsPerInch; // Calc physical properties // the Header property (should be called PageProperty...) holds // the physical width and height in TWIPS of the page // one twip is a 1/1440 of an inch! with WPRichText1.Header do begin // the page width and height are only internaly skipped when // printing in landscape if Landscape then begin // the metafile uses screen pixels so convert twips to screen resolution metaFile.Width := MulDiv(PageHeight, ScreenDpi, 1440); metaFile.Height := MulDiv(PageWidth, ScreenDpi, 1440); end else begin metaFile.Width := MulDiv(PageWidth, ScreenDpi, 1440); metaFile.Height := MulDiv(PageHeight, ScreenDpi, 1440); end; end; // calc the output rectangle (rectangle the richt text shall print) outRect:=Rect(0, 0, metaFile.Width, metaFile.Height); // draw metafile to the pdf printer PDFPrinter.BeginDoc; try // ############################################## // ##### Print for counter:=0 to WPRichText1.CountPages-1 do begin metaFileCanvas := TMetafileCanvas.Create(metaFile, 0); try // print normal page WPRichText1.PrintPageOnCanvas(metaFileCanvas, outRect, counter, [ppmUseBorders] ,100); finally metaFileCanvas.Free; end; PDFPrinter.DrawMetafileEx(0, 0, round(outRect.Right / 96 * 72), // resize down to 72dpi which is the standard res for pdf! round(outRect.Bottom / 96 * 72), metaFile.Handle,96,96); // 96 means screen resolution end; finally PDFPrinter.EndDoc; end; finally metaFile.Free; watermark.Free; end;end;
Code used for high res pdf printing:
Code
//ScreenDpi:=Screen.PixelsPerInch;
PDFPrinter.BeginDoc;
ScreenDPI := Getdevicecaps(PDFPrinter.Canvas.Handle, LOGPIXELSY);
// Calc physical properties
// the Header property (should be called PageProperty...) holds
// the physical width and height in TWIPS of the page
// one twip is a 1/1440 of an inch!
with WPRichText1.Header do
begin
// the page width and height are only internaly skipped when
// printing in landscape
if Landscape then
begin
// the metafile uses screen pixels so convert twips to screen resolution
metaFile.Width := MulDiv(PageHeight, ScreenDPI, 1440);
metaFile.Height := MulDiv(PageWidth, ScreenDPI, 1440);
end
else
begin
metaFile.Width := MulDiv(PageWidth, ScreenDPI, 1440);
metaFile.Height := MulDiv(PageHeight, ScreenDPI, 1440);
end;
end;
// calc the output rectangle (rectangle the richt text shall print)
outRect:=Rect(0, 0, metaFile.Width, metaFile.Height);
// draw metafile to the pdf printer
try
// ##############################################
// ##### Print
for counter:=0 to WPRichText1.CountPages-1 do
begin
metaFileCanvas := TMetafileCanvas.Create(metaFile, PDFPrinter.Canvas.Handle);
try
// print normal page
WPRichText1.PrintPageOnCanvas(metaFileCanvas, outRect, counter, [ppmUseBorders] ,100);
finally
metaFileCanvas.Free;
end;
metafile.SaveToFile('C:\test.emf');
PDFPrinter.DrawMetafileEx(0, 0, 0, 0, metaFile.Handle, ScreenDPI, ScreenDPI);
end;
finally
PDFPrinter.EndDoc;
end;
finally
metaFile.Free;
watermark.Free;
end;
Alles anzeigen
Any glue, what this could be or better: how can I increase the resolution
other than this way??
kind regards
Rabatscher Michael