WPForm

Top  Previous  Next

WPForm is a component set to provide a tool to create labels and forms with ease. It has the ability to create lists as well. Its user interface is intuitive and cusomizable - you dont have to provide the enduser a tool which provides too many features to explain - in WPForm you can customize everything!

 

To create metafiles with WPForm you can use this code:

 

var meta : TMetafile;

   i : Integer;

begin

  Init;

  WPPDFPrinter1.BeginDoc;

  meta := nil;

  for i:=1 to FD.PageCount do

  try

    meta :=  GetMetafile(i);

    WPPDFPrinter1.DrawMetafile(0,0,meta.handle);

  finally

    meta.Free;

  end;

  WPPDFPrinter1.EndDoc;

end;

 

This is the function which creates the metafiles:

 

function TForm1.GetMetaFile(PageNo: Integer): TMetaFile;

var

 FCanvas: TMetafileCanvas;

 PageSize: TWPFPageSize;

 Twips: Integer;

 PixelsPerInch: Integer;

 Width, Height: Integer;

 DC: Cardinal;

begin

 PageSize := FD.PageSize(PageNo);

 Result := TMetafile.Create;

 try

   DC := GetDc(FD.Handle);

   try

     Twips := PageSize.PageWidthTW;

     PixelsPerInch := GetDeviceCaps(HDC(DC), LOGPIXELSX);

     Width := Round((Twips / 1440) * PixelsPerInch);

 

     Twips := PageSize.PageHeightTW;

     PixelsPerInch := GetDeviceCaps(HDC(DC), LOGPIXELSY);

     Height := Round((Twips / 1440) * PixelsPerInch);

   finally

     ReleaseDC(FD.Handle,DC);

   end;

 

   Result.SetSize(Width, Height);

   Result.Enhanced := TRUE;

 

   FCanvas   := TMetafileCanvas.CreateWithComment(Result,

     0,

     'WPForm - www.wptools.com','');

   try

     FD.PrintPageOnCanvas(FCanvas,PageNo,0,0);

   finally

     FCanvas.Free;

   end;

 except

   Result.Free;

   raise;

 end;

end;

 

If you need to redirect the printing of the preview dialog (such as a report or labels) you can set the property TWPPreviewDlg.CustomPrinting to true and use the three printing events to create output:

 

// WPFPreviewDlg1.CustomPrinting muse be TRUE

 

procedure TForm1.WPFPreviewDlg1CustomPrintEnd(Sender: TWPFReportEngine;

 FormEditor: TWPFormEditor);

begin

 WPPDFPrinter1.EndDoc;

end;

 

procedure TForm1.WPFPreviewDlg1CustomStartPrint(Sender: TWPFReportEngine;

 FormEditor: TWPFormEditor; var Abort: Boolean);

begin

 WPPDFPrinter1.Filename := 'c:\testwpform.pdf';

 WPPDFPrinter1.AutoLaunch := TRUE;

 WPPDFPrinter1.BeginDoc;

end;

 

procedure TForm1.WPFPreviewDlg1CustomPrintPage(Sender: TWPFReportEngine;

 FormEditor: TWPFormEditor; PageNo: Integer; var Abort: Boolean);

var res : Integer;

begin

 res := Screen.PixelsPerInch;

 WPPDFPrinter1.StartPage(

   MulDiv(FormEditor.Page.PageWidthTW,res,1440),

   MulDiv(FormEditor.Page.PageHeightTW,res,1440),

   res,res,0);  

try

 FormEditor.PrintPageOnCanvasZoom(WPPDFPrinter1.Canvas, PageNo, 0, 0, 100);

finally

   WPPDFPrinter1.EndPage;

end;

end;

 

It is also possible to create the PDF without first showing the the preview.

Please use the above code but instead of showing the report with

 

// Create report/labels and show it

WPFPreviewDlg1.PreviewReport(WPFReportEngine1);

 

Print it at once with

 

// Create report/labels and PRINT

WPFPreviewDlg1.PrintReport(WPFReportEngine1);