<< Click to Display Table of Contents >> Navigation: Commands > Printing (on device) > PrintHDC |
The Delphi VCL implements wrapping methods which can be directly called:
function TWPViewPDF.PrintHDC(
PageNo: Integer;
DC: HDC;
ResXOrW, ResYOrH: Integer): Boolean;
var
IsW, IsH: Integer;
begin
Result := PrintHDC(PageNo, DC, ResXOrW, ResYOrH, IsW, IsH);
end;
function TWPViewPDF.PrintHDC(
PageNo: Integer;
DC: HDC;
ResXOrW, ResYOrH: Integer;
var IsW, IsH: Integer) : Boolean;
var
wh: Integer;
begin
CommandEx(COMPDF_PrintHDCSetXRes, ResXOrW);
CommandEx(COMPDF_PrintHDCSetYRes, ResYOrH);
// 1. Set Pagenumber
CommandEx(COMPDF_PrintHDC_SelectPage, PageNo);
// 2. Print using this page number
wh := CommandEx(COMPDF_PrintHDC_SelectedPage, DC);
if wh = -1 then
Result := false
else
begin
IsW := (wh shr 16) and $FFFF;
IsH := wh and $FFFF;
Result := (IsW > 0) and (IsH > 0);
end;
end;
Example:
PaintBox1.Canvas.Lock; // REQUIRED!
try
WPViewPDF1.PrintHDC( 0, PaintBox1.Canvas.Handle,
- PaintBox1.Width, -PaintBox1.Height );
finally
PaintBox1.Canvas.Unlock;
end;
Also see the PDFWorkBench example.
It is very useful to render PDF on any HDC.