Printing - Page number paradox

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Printing - Page number paradox

Post by Pablo César »

Ok, Claudio. Thank you.

I was looking into new release. I am compiling all demos at SAMPLES.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Pablo César wrote: Wed Mar 29, 2017 5:44 pm Hi Karl, have you be welcome to our community.
Sorry I did not understand you regarding button, pages.
I translated your short code but I did not understood.
Hi Pablo,

sorry for not answering immediately but the first two sunny spring days kept me from work. Thank you for your interest. My program is a very big ERP-program and the submitted code is only a little part of it. The program is for companies who build and repair truck-bodies and trailers. The workers get a written order with one or 2-4 pages. Even from the first page on they must definitly know how many pages contains the whole document. I´m working with RICHEDITBOX because I need RTF-files. The "HEADER" is going over the whole A4-page and repeats itself on each page. When HMG-PRINTVIEW-window appears, the program knows exactly, how many pages the document will have. With the variable "pages" I get the number of pages. By pushing the close-button of the PREVIEW-window again (_exit24.bmp) the whole cycle but without asking for the printers repeats. My problem is, how to get this button pushed automatically twice.

Best regards
Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Printing - Page number paradox

Post by Rathinagiri »

I think you don't need to get the button pushed twice. You can call the same function again which is called with the button action procedure. Right?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Rathinagiri wrote: Fri Mar 31, 2017 4:26 pm I think you don't need to get the button pushed twice. You can call the same function again which is called with the button action procedure. Right?
Hi Rathi,

Thank you for your interest too. You are very right. I made a mistake by telling you to push the button twice. You need only push once. In my litte code you can see, that it works. But when the program during printing finds, that there are more pages, it should go on without pushing the button. Is there any possibility to change the source code ?

Thanks in advance
Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Printing - Page number paradox

Post by Rathinagiri »

Yes. You have to call your own "Function RichEditBox_RTFPrint" as in h_richeditbox.prg in sources directory starting line number 385.

There in the first pass you have to give ABORT PRINTDOC and in the second pass you can give END PRINTDOC. First pass can be without preview and Second pass can be with preview.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Rathinagiri wrote: Sat Apr 01, 2017 8:11 am Yes. You have to call your own "Function RichEditBox_RTFPrint" as in h_richeditbox.prg in sources directory starting line number 385.
Thank you very much Rathi for this tip. This means a lot of work for me because I never before changed source code or used parts of it in my own code. If I am successful, I will inform you immediately. Now I try.....

Best regards Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Printing - Page number paradox

Post by Rathinagiri »

You need not modify source code or re-build the library.

Instead you copy the function RichEditBox_RTFPrint into your code and rename it like RichEditBox_MyRTFPrint and call this function in your code wherever you have used RTFPrint.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Printing - Page number paradox

Post by Rathinagiri »

First you try to run without modifying the source code but by calling your own function. Then try to modify your own function. You can be successful.

Call in your code :

Instead of
Form_81.Edit_1.RTFPrint (aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)

You use
RichEditBox_MyRTFPrint( Form_81.Edit_1.handle, aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)

Copy the code below into your code.

Code: Select all

*----------------------------------------------------------------------------------------------------------*
Function RichEditBox_MyRTFPrint ( hWndControl, aSelRange, nLeft, nTop, nRight, nBottom, PrintPageCodeBlock )
*----------------------------------------------------------------------------------------------------------*
LOCAL nPageWidth, nPageHeight
LOCAL nNextChar := 0
LOCAL nTextLength := RichEditBox_GetTextLength ( hWndControl )

   DEFAULT aSelRange          TO { 0, -1 }   // select all text
   DEFAULT nLeft              TO 20          // Left   page margin in millimeters
   DEFAULT nTop               TO 20          // Top    page margin in millimeters
   DEFAULT nRight             TO 20          // Right  page margin in millimeters
   DEFAULT nBottom            TO 20          // Bottom page margin in millimeters
   DEFAULT PrintPageCodeBlock TO {|| NIL}

   nPageWidth  := OpenPrinterGetPageWidth()    // in millimeters
   nPageHeight := OpenPrinterGetPageHeight()   // in millimeters

   nRight  := nPageWidth  - nRight
   nBottom := nPageHeight - nBottom

   // Convert millimeters in twips ( 1 inch = 25.4 mm = 1440 twips )
   nLeft   := nLeft   * 1440 / 25.4
   nTop    := nTop    * 1440 / 25.4
   nRight  := nRight  * 1440 / 25.4
   nBottom := nBottom * 1440 / 25.4

   IF aSelRange [2] == -1 .OR. aSelRange [2] > nTextLength
      aSelRange [2] := nTextLength
   ENDIF

   START PRINTDOC
   DO WHILE nNextChar < nTextLength
      START PRINTPAGE
          EVAL ( PrintPageCodeBlock )
          nNextChar := RichEditBox_FormatRange ( hWndControl, OpenPrinterGetPageDC(), nLeft, nTop, nRight, nBottom, aSelRange )
          aSelRange [1] := nNextChar
          DO EVENTS
      END PRINTPAGE
   ENDDO
   END PRINTDOC

Return Nil
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Rathinagiri wrote: Sat Apr 01, 2017 3:34 pm First you try to run without modifying the source code but by calling your own function. Then try to modify your own function. You can be successful.
Rathi this was a very great help for me. Thanks a lot. I would have never figured out to go with the call RichEditBox_myRTFPrint(Form_81.Edit_1.handle, ...........). But first I had to delete the DEFAULTs in the call. Now it works. The main goal was to push the close button by the program. I´m going on now and will report to you if I will be sucessful. :D

Kind regards from Ulm-Germany
Karl
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Printing - Page number paradox

Post by Rathinagiri »

The idea of double pass is so simple.

In the first pass, you run a pseudo printing just to find out the number of pages. Then in the second pass you can run with the real printing.

To do the pseudo printing, you can use the following...

First pass:

Code: Select all

SELECT PRINTER default TO lSuccess // just a dummy printer if you want to specify the page size, you can fix that also here.
In the MyRTFPrint function

Code: Select all

   pages := 0
   START PRINTDOC
   DO WHILE nNextChar < nTextLength
      START PRINTPAGE
      pages ++
          EVAL ( PrintPageCodeBlock )
          nNextChar := RichEditBox_FormatRange ( hWndControl, OpenPrinterGetPageDC(), nLeft, nTop, nRight, nBottom, aSelRange )
          aSelRange [1] := nNextChar
          DO EVENTS
      END PRINTPAGE
   ENDDO
   ABORT PRINTDOC
By this way, you can find out the exact number of pages. See, you are aborting the dummy print procedure. In the second pass you can continue with preview.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply