Calculate total pages
Re: Calculate total pages
Hi João,
we are required by law to print a QR code on every invoice. In the invoice preview, you don't know yet whether you will actually print
or if changes are still needed.
Here you see the invoice without a QR code. During printing, the QR code is then added and stored as a metafile.
In the hotel, we then have to print the payment method on the copy. Printing anew with data, for example from the DBF file,
is not a copy, as you could change the values here.
For us, it is now like it used to be with the stamp: Invoice paid in cash.
Best regards,
Otto
we are required by law to print a QR code on every invoice. In the invoice preview, you don't know yet whether you will actually print
or if changes are still needed.
Here you see the invoice without a QR code. During printing, the QR code is then added and stored as a metafile.
In the hotel, we then have to print the payment method on the copy. Printing anew with data, for example from the DBF file,
is not a copy, as you could change the values here.
For us, it is now like it used to be with the stamp: Invoice paid in cash.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
Re: Calculate total pages
Master Otto, master Otto!! Are you trying to trick me? hahahahaha.
I asked for a PRACTICAL EXAMPLE with Fonte(.PRG) where you use this subclass model that you post.
There is no way to fool the biggest super power of FIVEWIN BRASIL.
hahahahahahaha.
¡¡Maestro Otto, maestro Otto!! ¿Estás tratando de engañarme? jajajajaja.
Pedí un EJEMPLO PRÁCTICO con Fonte(.PRG) donde usas este modelo de subclase que publicas.
No hay forma de engañar a la mayor superpotencia de FIVEWIN BRASIL.
jajajajajajaja.
BROMA, BROMA, BROMA!!
Gracias, thanks.
Regards, saludos.
I asked for a PRACTICAL EXAMPLE with Fonte(.PRG) where you use this subclass model that you post.
There is no way to fool the biggest super power of FIVEWIN BRASIL.
hahahahahahaha.
¡¡Maestro Otto, maestro Otto!! ¿Estás tratando de engañarme? jajajajaja.
Pedí un EJEMPLO PRÁCTICO con Fonte(.PRG) donde usas este modelo de subclase que publicas.
No hay forma de engañar a la mayor superpotencia de FIVEWIN BRASIL.
jajajajajajaja.
BROMA, BROMA, BROMA!!
Gracias, thanks.
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Re: Calculate total pages
Hi João,
I've also made changes to preview.prg. When the invoice button is pressed, these steps are executed:
Best regards,
Otto
I've also made changes to preview.prg. When the invoice button is pressed, these steps are executed:
Best regards,
Otto
Code: Select all | Expand
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.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Calculate total pages
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.
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.
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
Modification-3: Add this function at the end of printer.prg:
Now let us do this small test:
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.
We can modify an emf file in two ways:I save an emf file and then reopen add the number and print it.
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.
That means, first a dry-run to count pages and then final run using the count.PRINT oPrn NAME "My Print" CALCULATE
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
Code: Select all | Expand
DATA cLastPage INIT "#PGC#"
Locate these lines
Code: Select all | Expand
if oPrinter:lMeta
if Empty( oPrinter:cFile )
Code: Select all | Expand
if oPrinter:lMeta
PageNumber( oPrinter )
if Empty( oPrinter:cFile )
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
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Silvio.Falconi
- Posts: 7104
- Joined: Thu Oct 18, 2012 7:17 pm
Re: Calculate total pages
Is It possible also with treport?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
- MarcoBoschi
- Posts: 1070
- Joined: Thu Nov 17, 2005 11:08 am
- Location: Padova - Italy
- Contact:
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Calculate total pages
YesSilvio.Falconi wrote:Is It possible also with treport?
Where you write page number, write something like this:
Code: Select all | Expand
"Page : " + cValToChar( nPage ) + ;
" of " + oRep:oDevice:cLastPage
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Silvio.Falconi
- Posts: 7104
- Joined: Thu Oct 18, 2012 7:17 pm
Re: Calculate total pages
Nages,nageswaragunupudi wrote:YesSilvio.Falconi wrote:Is It possible also with treport?
Where you write page number, write something like this:Code: Select all | Expand
"Page : " + cValToChar( nPage ) + ; " of " + oRep:oDevice:cLastPage
There is something not run ok on Treport
I made
oRep:oTitle := TrLine():New( {{|| cf(date())+"- Pagina : "+Str(oRep:nPage,3)+"/"+(oRep:oDevice:cLastPage)} }, oRep, 2 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
- Silvio.Falconi
- Posts: 7104
- Joined: Thu Oct 18, 2012 7:17 pm
Re: Calculate total pages
Perhaps I found the solution
rem "static" form PageNumber function on Tprinter class
then add this line pn this method
With
But run bad because I have to print 3 pages and I have
1 - ok
2 - ok
3 -bad
solution ?
rem "static" form PageNumber function on Tprinter class
then add this line pn this method
Code: Select all | Expand
METHOD End() CLASS TReport
::lFinish := .t.
if ! ::lCreated .or. ! ::lStable
Code: Select all | Expand
METHOD End() CLASS TReport
::lFinish := .t.
PageNumber( ::oDevice)
if ! ::lCreated .or. ! ::lStable
But run bad because I have to print 3 pages and I have
1 - ok
2 - ok
3 -bad
solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Calculate total pages
Great idea, but the EMF that is produced here are pure binaries, no readable text inside them. What am I doing wrong?nageswaragunupudi wrote:For now, we can do this test.
First let us make a few modifications to the Printer.prg:
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Calculate total pages
Yes, true.
But the text we print is stored in wide format.
If we printed "Name", it is stored as AnsiToWide( "Name" ), i.e., "N" + Chr(0) + "a" + Chr(0) + "m" + Chr( 0 ) + "e" + Chr( 0 ).
In other words the text is encoded in UTF16LE format.
So, if we want to substitute "Name" with "NAME", we can use StrTran( cEmf, AnsiToWide( "Name" ), AnsiToWide( "NAME" ) )
If we deal with English ( ANSI encoded text ), it is enough to use AnsiToWide, but for utf8 text, we need to convert to utf16le, using fwh functon StrToWide( cText, .f. ) or any other similar function.
But the text we print is stored in wide format.
If we printed "Name", it is stored as AnsiToWide( "Name" ), i.e., "N" + Chr(0) + "a" + Chr(0) + "m" + Chr( 0 ) + "e" + Chr( 0 ).
In other words the text is encoded in UTF16LE format.
So, if we want to substitute "Name" with "NAME", we can use StrTran( cEmf, AnsiToWide( "Name" ), AnsiToWide( "NAME" ) )
If we deal with English ( ANSI encoded text ), it is enough to use AnsiToWide, but for utf8 text, we need to convert to utf16le, using fwh functon StrToWide( cText, .f. ) or any other similar function.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Calculate total pages
It works, thank you!
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Calculate total pages
One caution.
Length of the WideString ( utf16le ) should not change.
Length of the WideString ( utf16le ) should not change.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Calculate total pages
Mr. Silvio
We will get back to you soon.
We will get back to you soon.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Calculate total pages
Of course.nageswaragunupudi wrote:One caution.
Length of the WideString ( utf16le ) should not change.