printing several pages

printing several pages

Postby plantenkennis » Fri Sep 21, 2018 9:09 am

Hello Antonio,

I have a printroutine that prints several pages with plantinformation. On every page I want to have the information on the same place. The number of pages is depending on the length of an array. I had a working function, but now I have a new printer and everything shifts to other position.

How can i make a print working on every printer the same.
Code: Select all  Expand view  RUN

PUBLIC nPage
PUBLIC nPagePx := 815

PUBLIC 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:SetSize( oPrn:pageWidth()-56 , (oPrn:pageHeight()) * LEN(aPrintArray))

FOR nPage = 1 TO LEN(aPrintArray)
    nRow := 56 + ((nPage-1)*nPagePx)
    @ nRow, nCol SAY oSay PROMPT cLatijnNaam OF oPrn SIZE 480, 40
        oSay:Setfont("Arial",20 )
        oSay:setTextColor(0,51,0,100)
    @ nRow+30, 285 IMAGE oImg OF oPrn SIZE 250, 250 FILENAME cFoto
        oImg:SetFrame()
NEXT
oPrn:run()

 


IF I vary nPagePx I can make it work, but I think this is depending on the printer installed. I want it to work with every printer/computer
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby Antonio Linares » Fri Sep 21, 2018 11:29 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby plantenkennis » Fri Sep 21, 2018 1:50 pm

Hello Antonio,

I am sorry, but I don't understand this code.
(I speak English, but not French :wink: )

I hope you can make me an exaple on how to use this.
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby Antonio Linares » Fri Sep 21, 2018 6:39 pm

Please add this line and test it with different printers and let me know what you get:

oPrn:AutoPage(.T.)
MsgInfo( oPrn:pageHeight() )
oPrn:SetSize( oPrn:pageWidth()-56 , (oPrn:pageHeight()) * LEN(aPrintArray))
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby plantenkennis » Sat Sep 22, 2018 10:13 am

Hello Antonio,

With several printers I get the same output: 841. According to my calculation that should be right, because I think 10 mm = 28,33 px.
So an A4 paper of 210*297 mm gives (21*28,33) 595 px width and (29,7*28,33) 841 height.

But if I use these numbers to set a new page, it doesn't fit...
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby Antonio Linares » Sat Sep 22, 2018 10:53 am

How many elements of aPrintArray would you like to fit in one page ?

I think it is the logic of your code what fails :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby plantenkennis » Sun Sep 23, 2018 11:33 am

Hello Antonio,

The number of elements that I want to print on a page very every page. But some elements always comes back on all the pages. I have made a little sample that shows the problem. If you click 'print' and browse through the pages in the preview you can see that all the lines shifts a bit every page. When I increase or decrease the value nPagePx I can make it not to shift as much, but I don't think that this is a good solution. As I told before, on one printer the value of 819 works great, on another printer I have to decrease it to 813.
Code: Select all  Expand view  RUN

#include "FiveMac.ch"

*a test program for printing multiple pages
*made by René Koot

FUNCTION Main()

   LOCAL oDlg
   
   DEFINE DIALOG oDlg TITLE "Dialog"
   
   @ 40, 40 BUTTON "print" OF oDlg ACTION RK_PrintTest()
   
   DEFINE MSGBAR OF oDlg
   
   ACTIVATE DIALOG oDlg
   
RETURN NIL  

*************************************************

FUNCTION RK_PrintTest()


LOCAL nCol := 28
LOCAL nRow := 0
LOCAL nRowHeight := 0
LOCAL n
LOCAL oSay, oImg

LOCAL aPrintArray[0][5]

AADD(aPrintArray, {'Line 1_1', 'Line2_1', 'Line3_1', 'Line4_1', 'Line5_1'})
AADD(aPrintArray, {'Line 1_2', 'Line2_2', 'Line3_2', 'Line4_2', 'Line5_2'})
AADD(aPrintArray, {'Line 1_3', 'Line2_3', 'Line3_3', 'Line4_3', 'Line5_3'})
AADD(aPrintArray, {'Line 1_4', 'Line2_4', 'Line3_4', 'Line4_4', 'Line5_4'})
AADD(aPrintArray, {'Line 1_5', 'Line2_5', 'Line3_5', 'Line4_5', 'Line5_5'})
AADD(aPrintArray, {'Line 1_6', 'Line2_6', 'Line3_6', 'Line4_6', 'Line5_6'})
AADD(aPrintArray, {'Line 1_7', 'Line2_7', 'Line3_1', 'Line4_1', 'Line5_1'})
AADD(aPrintArray, {'Line 1_8', 'Line2_8', 'Line3_2', 'Line4_2', 'Line5_2'})
AADD(aPrintArray, {'Line 1_9', 'Line2_9', 'Line3_3', 'Line4_3', 'Line5_3'})
AADD(aPrintArray, {'Line 1_10', 'Line2_10', 'Line3_4', 'Line4_4', 'Line5_4'})
AADD(aPrintArray, {'Line 1_11', 'Line2_11', 'Line3_5', 'Line4_5', 'Line5_5'})
AADD(aPrintArray, {'Line 1_12', 'Line2_12', 'Line3_6', 'Line4_6', 'Line5_6'})
AADD(aPrintArray, {'Line 1_13', 'Line2_13', 'Line3_1', 'Line4_1', 'Line5_1'})
AADD(aPrintArray, {'Line 1_14', 'Line2_14', 'Line3_2', 'Line4_2', 'Line5_2'})
AADD(aPrintArray, {'Line 1_15', 'Line2_15', 'Line3_3', 'Line4_3', 'Line5_3'})
AADD(aPrintArray, {'Line 1_16', 'Line2_16', 'Line3_4', 'Line4_4', 'Line5_4'})
AADD(aPrintArray, {'Line 1_17', 'Line2_17', 'Line3_5', 'Line4_5', 'Line5_5'})
AADD(aPrintArray, {'Line 1_18', 'Line2_18', 'Line3_6', 'Line4_6', 'Line5_6'})

PUBLIC nPage
PUBLIC nPagePx := 813

PUBLIC 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:SetSize( oPrn:pageWidth()-56 , (oPrn:pageHeight()-28) * LEN(aPrintArray))

FOR nPage = 1 TO LEN(aPrintArray)
    cFoto := "write.png"
    nRow := 56 + ((nPage-1)*nPagePx)
    @ nRow, nCol SAY oSay PROMPT aPrintArray[nPage,1] OF oPrn SIZE 480, 40
        oSay:Setfont("Arial",20 )
        oSay:setTextColor(0,51,0,100)
    @ nRow+30, 285 IMAGE oImg OF oPrn SIZE 250, 250 FILENAME cFoto
        oImg:SetFrame()
    nRow := nRow + 300
   
    @ nRow, nCol SAY oSay PROMPT aPrintArray[nPage,2] OF oPrn SIZE 240, 18
        oSay:Setfont("Arial",12 )
    nRow := nRow + 30
    @ nRow, nCol SAY oSay PROMPT aPrintArray[nPage,3] OF oPrn SIZE 240, 18
        oSay:Setfont("Arial",12 )
    nRow := nRow + 30
    @ nRow, nCol SAY oSay PROMPT aPrintArray[nPage,4] OF oPrn SIZE 240, 18
        oSay:Setfont("Arial",12 )
    nRow := nRow + 30
    @ nRow, nCol SAY oSay PROMPT aPrintArray[nPage,5] OF oPrn SIZE 240, 18
        oSay:Setfont("Arial",12 )
    nRow := nRow + 30
   
    RK_PrintFooter()
NEXT

oPrn:run()

RETURN NIL

*************************************************

FUNCTION RK_PrintFooter()

    @ 780 + ((nPage-1)*nPagePx), 28 SAY oSay PROMPT CHR(0169) + ' Copyright: Plantenkennis versie ' OF oPrn SIZE oPrn:pageWidth()- 112, 20
            oSay:Setfont("Arial",12 )
    @ 780 + ((nPage-1)*nPagePx), 450 SAY oSay PROMPT 'page ' + ALLTRIM(STR(nPage)) OF oPrn SIZE oPrn:pageWidth()- 112, 20
            oSay:Setfont("Arial",12 )

RETURN NIL

*************************************************

function PrinterPaint()
*somehow this function is needed for printing
return nil

 


I hope you have a solution for this, maybe I don't see an important setting?
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby plantenkennis » Tue Oct 02, 2018 4:49 am

Hello Antonio,

Did you have any time to look at my printing sample and how to get everything on the same position every page?
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby Antonio Linares » Tue Oct 02, 2018 6:49 pm

René,

I am checking it
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby Antonio Linares » Tue Oct 02, 2018 8:48 pm

René,

This way I am able to properly print on the first page though I get an empty (and undesired) second page:

Anyhow, using this code I am unable to print more than one page...
Code: Select all  Expand view  RUN
#include "FiveMac.ch"

static oPrn

function Main()

   local oDlg

   DEFINE DIALOG oDlg TITLE "Printer test"

   @ 40, 40 BUTTON "Print" OF oDlg ACTION Print()

   ACTIVATE DIALOG oDlg

return nil

function Print()

   oPrn = TPrinter():New()

   oPrn:SetLeftMargin( 0 )
   oPrn:SetRightMargin( 0 )
   oPrn:SetTopMargin( 0 )
   oPrn:SetBottomMargin( 0 )
   oPrn:SetPaperName( "A4" )
   oPrn:AutoPage( .T. )
   oPrn:SetSize( oPrn:PageWidth(), oPrn:PageHeight() - 60 )

   oPrn:Run()

return nil

function PrinterPaint()

   local nStep, n, nLine := 1

   nStep = ( oPrn:PageHeight() - 60 ) / 30 // 30 lines

   for n = 0 to oPrn:PageHeight() STEP nStep
      @ n, 0 SAY Str( nLine++ ) OF oPrn
   next

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby plantenkennis » Wed Oct 03, 2018 6:20 pm

Hello Antonio,

According to the sample 'testprint' we have to set pageHeight() to the height of the desired pages. As long as we set this to the height of one page there will never be a next page.

Is it not possible to build in some functions like StartPage() and EndPage() that starts and ends a page with settings set by pageheight()?
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: printing several pages

Postby Antonio Linares » Thu Oct 04, 2018 8:29 am

René,

Manuel Alvarez and I are reading Apple documentation about it:

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Printing/osxp_pagination/osxp_pagination.html

We may need some time to implement StartPage() and EndPage().

In the meantime, if you can keep using your current solution, that would be fine. Thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby Antonio Linares » Thu Oct 04, 2018 10:50 am

René,

Manuel has implemented a new Class TPrinter Method GetASizePrintable() that is working great! :-)

Here you have an example printing X pages:
Code: Select all  Expand view  RUN
#include "fivemac.ch"

static oPrn

function Main()

   local oDlg

   DEFINE DIALOG oDlg TITLE "Printer test"

   @ 40, 40 BUTTON "Print" OF oDlg ACTION Print()

   ACTIVATE DIALOG oDlg

return nil

function Print()

   local aSize

   oPrn = TPrinter():New()

   oPrn:SetLeftMargin( 0 )
   oPrn:SetRightMargin( 0 )
   oPrn:SetTopMargin( 0 )
   oPrn:SetBottomMargin( 0 )
   oPrn:SetPaperName( "A4" )
   oPrn:AutoPage( .T. )

   aSize = oPrn:GetASizePrintable()
   oPrn:SetSize( aSize[ 1 ], aSize[ 2 ] * 3 ) // 3 pages

   oPrn:Run()

return nil

function PrinterPaint()

   local nStep, n, nLine := 1
   local nHeight := oPrn:GetaSizePrintable()[ 2 ] * 3 // 3 pages

   nStep = nHeight / ( 30 * 3 ) // 30 lines * 3 pages

   for n = 1 to nHeight STEP nStep
      @ n, 0 SAY Str( nLine++ ) OF oPrn
   next

return nil


Please download the new FiveMac libs from here:
https://bitbucket.org/fivetech/fivemac/src/master/lib/

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby Antonio Linares » Thu Oct 04, 2018 4:37 pm

René,

We already have a first implementation of Class TPrinter Methods() StartPage() and EndPage().

Here you have an example of use. Hopefully the modified Class TPrinter does not break your existing code:

printer.prg // A new example of the FiveMac enhanced Class TPrinter
Code: Select all  Expand view  RUN
#include "FiveMac.ch"

function Main()

   local oDlg

   DEFINE DIALOG oDlg TITLE "Printer test"

   @ 40, 40 BUTTON "Print" OF oDlg ACTION Print()

   ACTIVATE DIALOG oDlg

return nil

function Print()

   local n, oPrn := TPrinter():New()

   for n = 1 to 10 // ten pages
      oPrn:StartPage()
     
         oPrn:Say( 0, 250, "Header " + Alltrim( Str( oPrn:nPages ) ) )
         oPrn:Say( oPrn:LastRow(), 250, "- Page " + Alltrim( Str( oPrn:nPages ) ) + " -" )

      oPrn:EndPage()
   next

   oPrn:Run()

return nil
 


Updated FiveMac libraries are available from here:
https://bitbucket.org/fivetech/fivemac/src/master/lib/
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42107
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: printing several pages

Postby plantenkennis » Sat Oct 06, 2018 2:34 pm

Hello Manuel and Antonio,

Thank you very much for all this work. I think with some addaptions this will work great. For now I miss the following:
    setting fontname -size and -color of the say
    printing images

If this is build in I can work with the new Class TPrinter.
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Next

Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 15 guests