Printing - Page number paradox

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Rathinagiri wrote: Sun Apr 02, 2017 11:32 am 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.
Before I read your example I tried several versions, but it ends always the same way. If the document has only one page it works fine. But if pages >1 the PREVIEW is a darkgrey screen. In the left upper edge is correctly Page1/2, Page 2/2. Therefor I send my code because I have no idea where my mistake is.

Code: Select all

*****************************   Beginn Auftrag-Druck   *************************
FUNCTION AuftragDruck
Private page      := 0, ;
        pages     := 0, ;
        lSuccess  := .F., ;
        pass      := 1

SELECT PRINTER DIALOG TO lSuccess PREVIEW
IF lSuccess
  aSelRange := {0,-1}
  PrintPageCodeBlock := {||page += 1, @ 0,0 PRINT Auftragskopf()}
  RichEditBox_MyRTFPrint(Form_81.Edit_1.Handle, aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)
  pages := page
  IF pages > 1
    pass += 1
    page := 0
    aSelRange := {0,-1}
    PrintPageCodeBlock := {||page += 1, @ 0,0 PRINT Auftragskopf()}
    RichEditBox_MyRTFPrint(Form_81.Edit_1.Handle, aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)
  ENDIF
ELSE
  MsgInfo('Drucker nicht bereit !')
ENDIF
RETURN NIL
************************    Ende AuftragsDruck   *******************************

*************************   Beginn RTFPrint changed   **************************
Function RichEditBox_MyRTFPrint ( hWndControl, aSelRange, nLeft, nTop, nRight, nBottom, PrintPageCodeBlock )

LOCAL nPageWidth, nPageHeight
LOCAL nNextChar := 0
LOCAL nTextLength := RichEditBox_GetTextLength ( hWndControl )

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
  pages := page
  IF pass = 1  
    IF pages > 1
      ABORT PRINTDOC  
    ELSE  
      END PRINTDOC
    ENDIF
  ELSE
    END PRINTDOC
  ENDIF
RETURN Nil
*************************   Ende RTFPrint changed   ****************************
WIN 10 64-bit, WIN 7 32-bit, HMG 3.4.4, 32-bit
Karl
Posts: 39
Joined: Tue Mar 14, 2017 12:24 pm
DBs Used: DBF

Re: Printing - Page number paradox

Post by Karl »

Hi Rathi,

seems that I was blind. I didn´t see your tip with the dummy printer. It´s really simple. Now it works, problem solved. Thanks again. :D

Code: Select all

*****************************   Beginn Auftrag-Druck   *************************
FUNCTION AuftragDruck
Private page      := 0, ;
        pages     := 0, ;
        lSuccess  := .F., ;
        pass      := 1

SELECT PRINTER DEFAULT TO lSuccess
IF lSuccess
  aSelRange := {0,-1}
  PrintPageCodeBlock := {||page += 1, @ 0,0 PRINT Auftragskopf()}
  RichEditBox_MyRTFPrint(Form_81.Edit_1.Handle, aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)
  pages := page
  pass += 1
  page := 0
  SELECT PRINTER DIALOG TO lSuccess PREVIEW
  aSelRange := {0,-1}
  PrintPageCodeBlock := {||page += 1, @ 0,0 PRINT Auftragskopf()}
  RichEditBox_MyRTFPrint(Form_81.Edit_1.Handle, aSelRange, 13, 95, 10, 75, PrintPageCodeBlock)
ELSE
  MsgInfo('Drucker nicht bereit !')
ENDIF
RETURN NIL
************************    Ende AuftragsDruck   *******************************

*************************   Beginn RTFPrint changed   **************************
Function RichEditBox_MyRTFPrint ( hWndControl, aSelRange, nLeft, nTop, nRight, nBottom, PrintPageCodeBlock )

LOCAL nPageWidth, nPageHeight
LOCAL nNextChar := 0
LOCAL nTextLength := RichEditBox_GetTextLength ( hWndControl )

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
  pages := page
  IF pass = 1  
    ABORT PRINTDOC  
  ELSE  
    END PRINTDOC
  ENDIF
RETURN Nil
*************************   Ende RTFPrint changed   ****************************
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 »

Exactly what I had expected! :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply