Hi Julian - Update
I think I have found a solution - it is to do with the initialisation of the FReferenceDC variable in your WPPDFR1 unit's GetCanvas function. I tried doing a DC := Canvas.Handle and this also gave the same error. The error was generated at the
FCanvas := TMetafileCanvas.Create(FMetafile, FReferenceDC);
statement, so as the only difference between the GetCanvas function's TMetafileCanvas.Create and the one that worked was the FReferenceDC.
Setting this to zero then allows canvas drawing. Ureka!
The altered code in WPPDFR1 is shown below:
function TWPCustomPDFExport.GetCanvas: TCanvas;
var
currX, currY: Integer;
DC: HDC;
begin
if FCanvas = nil then
begin
FMetafile := TMetafile.Create;
FMetafile.MMWidth := Round(FLastWidth / Fpage_xres * 2540); // 1/100 mm !
FMetafile.MMHeight := Round(FLastHeight / Fpage_yres * 2540);
FMetafile.Enhanced := TRUE;
FCanvas := TMetafileCanvas.Create(FMetafile, 0{FReferenceDC}); // Probem here!
FCanvas.Font.PixelsPerInch := Fpage_yres;
FCanvas.Brush.Style := bsClear;
DC := FCanvas.Handle;
currX := GetDeviceCaps(DC, LOGPIXELSX);
currY := GetDeviceCaps(DC, LOGPIXELSY);
SetMapMode(DC, MM_ANISOTROPIC);
SetWindowExtEx(DC, Fpage_xres, Fpage_yres, nil);
SetViewPortExtEx(DC, currX, currY, nil);
SetViewPortOrgEx(DC, 0, 0, nil);
SetWindowOrgEx(DC, 0, 0, nil);
end;
Result := FCanvas;
end;
Can you please let me know the implications of changing this value - I have not tested it on multiple page documents etc.
I would much rather have a fix that you are confident in.
Thanks,
Martin