Calculate total pages

Re: Calculate total pages

Postby Otto » Fri Nov 24, 2023 3:49 pm

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

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6003
Joined: Fri Oct 07, 2005 7:07 pm

Re: Calculate total pages

Postby karinha » Fri Nov 24, 2023 4:38 pm

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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7213
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Calculate total pages

Postby Otto » Fri Nov 24, 2023 6:24 pm

Hi João,

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 view

   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
********************************************************************
User avatar
Otto
 
Posts: 6003
Joined: Fri Oct 07, 2005 7:07 pm

Re: Calculate total pages

Postby nageswaragunupudi » Sat Nov 25, 2023 8:51 am

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
Code: Select all  Expand view
DATA   cLastPage INIT "#PGC#"


Modification-2: Small modification to function PrintEnd() in TPrinter.prg
Locate these lines
Code: Select all  Expand view
  if oPrinter:lMeta
      if Empty( oPrinter:cFile )

Insert one line
Code: Select all  Expand view
  if oPrinter:lMeta
      PageNumber( oPrinter )
      if Empty( oPrinter:cFile )
 

Modification-3: Add this function at the end of printer.prg:
Code: Select all  Expand view
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 view
#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


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate total pages

Postby Silvio.Falconi » Sat Nov 25, 2023 3:42 pm

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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: Calculate total pages

Postby MarcoBoschi » Sat Nov 25, 2023 3:42 pm

Many Thanks Mr Rao.
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Calculate total pages

Postby nageswaragunupudi » Sat Nov 25, 2023 3:52 pm

Silvio.Falconi wrote:Is It possible also with treport?


Yes
Where you write page number, write something like this:
Code: Select all  Expand view
"Page : " + cValToChar( nPage ) + ;
            " of " + oRep:oDevice:cLastPage
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate total pages

Postby Silvio.Falconi » Mon Nov 27, 2023 8:13 am

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
"Page : " + cValToChar( nPage ) + ;
            " of " + oRep:oDevice:cLastPage


Nages,
There is something not run ok on Treport

Image

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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: Calculate total pages

Postby Silvio.Falconi » Mon Nov 27, 2023 8:42 am

Perhaps I found the solution

rem "static" form PageNumber function on Tprinter class

then add this line pn this method
Code: Select all  Expand view

METHOD End() CLASS TReport

   ::lFinish := .t.


   if ! ::lCreated .or. ! ::lStable


With

Code: Select all  Expand view

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

Image


2 - ok

Image



3 -bad

Image

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
User avatar
Silvio.Falconi
 
Posts: 6768
Joined: Thu Oct 18, 2012 7:17 pm

Re: Calculate total pages

Postby Enrico Maria Giordano » Mon Nov 27, 2023 10:20 am

nageswaragunupudi wrote:For now, we can do this test.
First let us make a few modifications to the Printer.prg:


Great idea, but the EMF that is produced here are pure binaries, no readable text inside them. What am I doing wrong?
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Calculate total pages

Postby nageswaragunupudi » Mon Nov 27, 2023 12:27 pm

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Re: Calculate total pages

Postby nageswaragunupudi » Mon Nov 27, 2023 4:09 pm

One caution.
Length of the WideString ( utf16le ) should not change.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate total pages

Postby nageswaragunupudi » Mon Nov 27, 2023 4:10 pm

Mr. Silvio
We will get back to you soon.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10247
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Calculate total pages

Postby Enrico Maria Giordano » Mon Nov 27, 2023 4:22 pm

nageswaragunupudi wrote:One caution.
Length of the WideString ( utf16le ) should not change.


Of course.
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests