oDevice := DEVICE
aFiles := oDevice:aMeta
hMeta := oMeta1:hMeta
cUniqueID := cUniqueID()
CursorWait()
DeleteDC( oDevice:hDC)
oDevice := NIL
//cDoc, lUser, lPreview, xModel, lModal, lSelection
oDevice := PrintBegin( "Rechnung" + cUniqueID, , .F. , Setup():RGPrinter, .F. , .F. )
oDevice := PrintBegin( "Rechnung" + cUniqueID, , .F. , Setup():PDFPrinter, .F. , .F. )
StartDoc(oDevice:hDC, oDevice:cDocument )
StartPage( oDevice:hDC )
hMeta := GetEnhMetaFile(aFiles[nFor])
PlayEnhMetaFile( oDevice:hDC, hMeta,, .t. )
oDevice:hDCOut := oDevice:hDC
oDevice:CmSay( Setup():RgNr_ROW2, Setup():RgNr_COL2, Setup():VORSCHAUTXT , oPrnFont )
oDevice:SayBitmap( Setup():aQRCodePosition[ 1 ], Setup():aQRCodePosition[ 2 ],;
cBmpFile, Setup():aQRCodePosition[ 3 ], Setup():aQRCodePosition[ 3 ] )
copyfile(aFiles[nFor], Setup():Daten()+ "dataRg\" +"Rg-Nr_" + ALLTRIM(str(oRechnung:nRgNR()))+"_"+ ALLTRIM(str(nFor))+".emf", .F.)
DeleteEnhMetafile(hMeta)
EndPage(oDevice:hDC)
The code snippet you provided appears to be written in a language similar to Harbour or xBase, used for database applications. It's a routine for handling printing, specifically for generating invoices ("Rechnungen"). Here's a breakdown of what each part of the code is doing:
1. **Device and File Handling:**
- `oDevice := DEVICE`: Initializes an object `oDevice` to represent the current printing device.
- `aFiles := oDevice:aMeta`: Assigns metadata from the device to an array `aFiles`.
- `hMeta := oMeta1:hMeta`: Seems to reference a metafile handle from another object `oMeta1`.
2. **Unique ID Generation:**
- `cUniqueID := cUniqueID()`: Generates a unique ID, possibly for the invoice.
3. **Preparation for Printing:**
- `CursorWait()`: Possibly changes the cursor to a waiting state, indicating processing.
- `DeleteDC(oDevice:hDC)`: Deletes the current Device Context (DC) of the device.
- `oDevice := NIL`: Clears the device object.
- `oDevice := PrintBegin(...)`: Initializes a new print job with various parameters (like document name, printer setup, etc.). This is done twice, once presumably for a regular printer and once for a PDF printer.
4. **Document and Page Initialization:**
- `StartDoc(oDevice:hDC, oDevice:cDocument)`: Starts a new document in the device context.
- `StartPage(oDevice:hDC)`: Begins a new page in the document.
5. **Content Rendering:**
- The loop or logic to iterate through `aFiles` is not shown, but within that context:
- `hMeta := GetEnhMetaFile(aFiles[nFor])`: Retrieves an Enhanced Metafile from `aFiles`.
- `PlayEnhMetaFile(oDevice:hDC, hMeta,, .t.)`: Plays or renders the metafile onto the device context.
- `oDevice:hDCOut := oDevice:hDC`: Assigns the device context to another property, likely for output.
- The `oDevice:CmSay` and `oDevice:SayBitmap` calls seem to place text and bitmap images (like QR codes) on the document.
6. **File Management and Cleanup:**
- `copyfile(...)`: Copies the currently processed metafile to a specific directory.
- `DeleteEnhMetafile(hMeta)`: Deletes the Enhanced Metafile object to free up resources.
7. **Finalizing the Page and Document:**
- `EndPage(oDevice:hDC)`: Signals the end of a page in the print document.
Overall, this script is setting up a printing process, likely for invoices, involving both text and graphics (like QR codes), with the ability to output to both a physical printer and a PDF file. The use of metafiles suggests it's handling complex graphics or layouts.
I save an emf file and then reopen add the number and print it.
PRINT oPrn NAME "My Print" CALCULATE
DATA cLastPage INIT "#PGC#"
if oPrinter:lMeta
if Empty( oPrinter:cFile )
if oPrinter:lMeta
PageNumber( oPrinter )
if Empty( oPrinter:cFile )
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
#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
Silvio.Falconi wrote:Is It possible also with treport?
"Page : " + cValToChar( nPage ) + ;
" of " + oRep:oDevice:cLastPage
nageswaragunupudi wrote:Silvio.Falconi wrote:Is It possible also with treport?
Yes
Where you write page number, write something like this:
- Code: Select all Expand view RUN
"Page : " + cValToChar( nPage ) + ;
" of " + oRep:oDevice:cLastPage
METHOD End() CLASS TReport
::lFinish := .t.
if ! ::lCreated .or. ! ::lStable
METHOD End() CLASS TReport
::lFinish := .t.
PageNumber( ::oDevice)
if ! ::lCreated .or. ! ::lStable
nageswaragunupudi wrote:For now, we can do this test.
First let us make a few modifications to the Printer.prg:
nageswaragunupudi wrote:One caution.
Length of the WideString ( utf16le ) should not change.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 70 guests