We will be providing this feature in the next version.
In all cases other than direct printing to printer and generating PDF using HaruPDF, the printer class generates meta files for preview and then printing or for generation of pdf, jpg, docx, etc
In the case where meta files are generated we can modify the emf files with the total number of pages like Mr.Otto said.
I save an emf file and then reopen add the number and print it.
We can modify an emf file in two ways:
1. Open the emf file into hDC and directly overprint the new text and save. But this has to be done by the programmer.
2. For very minor changes, like over-writing the number of total pages, we can simply read the emf file as text, modify the text and save it.
For other cases like direct printing to printer and using HarruPdf, Mr. Marco's suggestion may be useful.
PRINT oPrn NAME "My Print" CALCULATE
That means, first a dry-run to count pages and then final run using the count.
But whatever we do, this should be transparent to the programmer and should happen without expecting the programmer to do any additional work.
For now, we can do this test.
First let us make a few modifications to the Printer.prg:
Modification-1: Add a new data
Modification-2: Small modification to function PrintEnd() in TPrinter.prg
Locate these lines
Insert one line
Code: Select all | Expand
if oPrinter:lMeta
PageNumber( oPrinter )
if Empty( oPrinter:cFile )
Modification-3: Add this function at the end of printer.prg:
Code: Select all | Expand
static function PageNumber( oPrn )
local cFor := AnsiToWide( oPrn:cLastPage )
local cTot := PadR( cValToChar( Len( oPrn:aMeta ) ), 5 )
local cMeta, n
oPrn:cLastPage := cTot
cTot := AnsiToWide( cTot )
for n := 1 to Len( oPrn:aMeta )
cMeta := MEMOREAD( oPrn:aMeta[ n ] )
if cFor $ cMeta
cMeta := StrTran( cMeta, cFor, cTot )
MEMOWRIT( oPrn:aMeta[ n ], cMeta )
else
EXIT
endif
next
return nil
Now let us do this small test:
Code: Select all | Expand
#include "fivewin.ch"
function Main()
local oPrn, oFont, oBold, n
PRINT oPrn PREVIEW
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-10 OF oPrn
DEFINE FONT oBold NAME "VERDANA" SIZE 0,-24 OF oPrn
for n := 1 to 6
PAGE
@ 0.5, 0 PRINT TO oPrn TEXT "Page : " + cValToChar( n ) + ;
" of " + oPrn:cLastPage ;
SIZE 8,0.3 INCHES ALIGN "T" FONT oFont
@ 1, 0 PRINT TO oPrn TEXT "Month:" + CRLF + NTOCMONTH( n ) SIZE 8,2 INCHES ALIGN "" ;
FONT oBold
ENDPAGE
next
ENDPRINT
RELEASE FONT oFont, oBold
return nil
