Page 4 of 5

Re: Printing - Page number paradox

Posted: Wed Mar 29, 2017 8:48 pm
by Pablo César
Ok, Claudio. Thank you.

I was looking into new release. I am compiling all demos at SAMPLES.

Re: Printing - Page number paradox

Posted: Fri Mar 31, 2017 4:05 pm
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

Re: Printing - Page number paradox

Posted: Fri Mar 31, 2017 4:26 pm
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?

Re: Printing - Page number paradox

Posted: Sat Apr 01, 2017 6:34 am
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

Re: Printing - Page number paradox

Posted: Sat Apr 01, 2017 8:11 am
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.

Re: Printing - Page number paradox

Posted: Sat Apr 01, 2017 2:57 pm
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

Re: Printing - Page number paradox

Posted: Sat Apr 01, 2017 3:23 pm
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.

Re: Printing - Page number paradox

Posted: Sat Apr 01, 2017 3:34 pm
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

Re: Printing - Page number paradox

Posted: Sun Apr 02, 2017 8:40 am
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

Re: Printing - Page number paradox

Posted: Sun Apr 02, 2017 11:32 am
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.