Page 1 of 1

printing on portrait or landscape paper

Posted: Tue May 28, 2019 6:16 pm
by plantenkennis
Hello,

While printing we can set the oriantation of the paper to portrait or landscape. But the number of rows we can print stay the same, Look at this sample. As you change oPrn:SetPagOrientation(0) to oPrn:SetPagOrientation(1) there are still 37 lines on the paper, but the spacing between the lines is smaller. Also the code to print the pagenumber does not work.

Code: Select all

FUNCTION RK_TestPrint()

LOCAL nPage := 1
LOCAL nCol := 28    && the column we start printing
LOCAL nRow := 1 && the row we start printing
LOCAL cText := ''
LOCAL oPrn:=TPrinter():new(0,0,0,0)

oPrn:SetLeftMargin(0)
oPrn:SetRightMargin(0)
oPrn:SetTopMargin(0)
oPrn:SetbottomMargin(0)
oPrn:setPaperName("A4")
*oPrn:AutoPage(.T.)
oPrn:SetPagOrientation(0)

oPrn:StartPage()

FOR n = 1 TO 100
    cText := 'This is line: ' + ALLTRIM(STR(nRow))

    @ nRow, 28 SAY oSay PROMPT cText OF oPrn PAGINED SIZE 300, 20 
            oSay:Setfont(Arial,12 )
    nRow++

    IF nRow > oPrn:LastRow()-2
        @ oPrn:LastRow(), 450 SAY oSay PROMPT 'page ' + ALLTRIM(STR(nPage)) OF oPrn PAGINED SIZE 300, 20 
            oSay:Setfont(Arial,12 )
        nPage++
        nRow := 1
        oPrn:EndPage()
        oPrn:StartPage()
    ENDIF

NEXT


oPrn:EndPage()

oPrn:run()

RETURN NIL
 
Can we change the number of lines that are printed on the paper OR change the spacing between the lines.

Re: printing on portrait or landscape paper

Posted: Wed May 29, 2019 12:46 pm
by mastintin
Change method setpagOrinetation () to this

Code: Select all

METHOD SetPagOrientation( nOrientation ) CLASS TPrinter

    PrnInfoPagSetOrientation( ::hPrnInfo, nOrientation )
    if nOrientation == 0
       ::nRowsPerPage := 40
    elseif nOrientation == 1
       ::nRowsPerPage := 20
    endif

return nil

 
See if nRowperpage is good in 20 for you.

And new method ...

Code: Select all

 METHOD GetPagOrientation() INLINE PrnInfoPagGetOrientation( ::hPrnInfo )
 

Code: Select all

HB_FUNC( PRNINFOPAGGETORIENTATION)
{
  NSPrintInfo * pi = ( NSPrintInfo *   ) hb_parnl( 1 );
  NSInteger nOrientation = pi.orientation ;
  hb_retnl( ( HB_LONG ) nOrientation );
}
 

Re: printing on portrait or landscape paper

Posted: Wed May 29, 2019 6:00 pm
by plantenkennis
Hello Manuel,

This looks good I think. But how if we print in a large fontsize? Is it possible to set the nSetrowPerPage just like set PageOrientation?

Re: printing on portrait or landscape paper

Posted: Wed May 29, 2019 6:19 pm
by mastintin
plantenkennis wrote:Hello Manuel,

This looks good I think. But how if we print in a large fontsize? Is it possible to set the nSetrowPerPage just like set PageOrientation?
Yes of course.
You can adjust the number of lines you want both horizontally and vertically.
LastRow will be ::nRowsPerPage - 1 .

...
oPrn:SetPagOrientation(0)
oPrn:nRowsPerPage := 33
----

Re: printing on portrait or landscape paper

Posted: Thu May 30, 2019 8:58 pm
by plantenkennis
Hello Manuel,

That looks perfect. I assume I need a new lib for this function? I dod not see one on BitBucket...

Re: printing on portrait or landscape paper

Posted: Fri May 31, 2019 6:39 am
by mastintin
Right now, I have problems with bitbucket ,I have uploaded the changes to repository but libs not upload .
for the moment you can use it directly on your code.

Code: Select all


local nOrinetation := 0
.....
oPrn:SetTopMargin(0)
oPrn:SetbottomMargin(0)
oPrn:setPaperName("A4")
*oPrn:AutoPage(.T.)

nOrientation := 1 
oPrn:SetPagOrientation( nOrientation)
  if nOrientation == 0
       oPrn:nRowsPerPage := 40  // your rows
    elseif nOrientation == 1
       oprn:nRowsPerPage := 20 // your rows 
    endif
...........

 
I'm sorry for the problems.
regards.

//-------------- edit --------------------

New libs is uploaded , make a copy of the previous ones and check that you do not create problems.

Re: printing on portrait or landscape paper

Posted: Fri May 31, 2019 12:03 pm
by plantenkennis
Hello Manuel,

Thank you very much, with the new libs it works perfect. :D

Another question: Can we also set the papersize to A5 or A3 (portrait and landscape)?

Re: printing on portrait or landscape paper

Posted: Mon Apr 13, 2020 5:08 pm
by omarlopez
good post!