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