GraDemo |
This sample program GraDemo.PRG, illustrates the use of the XPPPDF.CH preprocessor file to assist in the conversion of existing reports to use the XbpPDF class and create PDF files.
#include "xbp.ch"
#include "gra.ch"
#include "common.ch"
#include "xbpdev.ch"
#include "appevent.ch"
#include "xpppdf.ch"
#pragma library("XppPDF61.lib")
PROCEDURE MAIN
aSize := { 590, 780 }
aPos := { 0, 50 }
oDlg := xbpDialog():New( AppDesktop(), , aPos, {612, 822} )
oDlg:Create()
oPs := oDlg:DrawingArea:LockPS()
oFont := xbpFont():New( oPs )
oFont:Create( '24.Times New Roman' )
oPdf := xbppdf():New()
oPdf:Create( "gra.pdf" )
oPdf:NewPage( , , , , ,1 )
Report( oPdf )
oPdf:EndDoc(.t.)
Report( oPs )
nEvent := 0
do while nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @obr )
obr:handleEvent( nEvent, mp1, mp2 )
Enddo
Return
Function Report( oPs )
LOCAL aAttra
aAttra := array(GRA_AA_COUNT)
aAttra[GRA_AA_COLOR] := GRA_CLR_WHITE
GraSetAttrArea( oPs, aAttra )
GraBox( oPs, {10,10}, aSize, GRA_OUTLINEFILL)
aAttra[GRA_AA_COLOR] := GRA_CLR_YELLOW
GraSetAttrArea( oPs, aAttra )
GraBox( oPs, {100, 100}, {512, 692}, GRA_OUTLINEFILL)
GraSetFont( oPs, oFont )
GraSetColor( oPs, GRA_CLR_BLUE )
GraStringAt( oPs, {230, 400}, "Hello world!" )
RETURN(.t.)
// This function ReportPDF bellow, is equivalent to function Report above with a PDF object as a parameter, XbpPDF class will analyze the object
// parameter, and if it is a XbpPDF object will call the appropriate class methods instead of normal Xbase++ functions.
//
// Note that if you call the method directly, you should not pass the PDF object as a parameter.
Function ReportPDF( )
LOCAL aAttra
aAttra := array(GRA_AA_COUNT)
aAttra[GRA_AA_COLOR] := GRA_CLR_WHITE
oPdf:GraSetAttrArea( aAttra )
oPdf:GraBox( {10,10}, aSize, GRA_OUTLINEFILL)
aAttra[GRA_AA_COLOR] := GRA_CLR_YELLOW
oPdf:GraSetAttrArea( aAttra )
oPdf:GraBox( {100, 100}, {512, 692}, GRA_OUTLINEFILL)
oPdf:GraSetFont( oFont )
oPdf:GraSetColor( GRA_CLR_BLUE )
oPdf:GraStringAt( {230, 400}, "Hello world!" )
RETURN(.t.)