Announcement

Collapse
No announcement yet.

How to Xprint multiple pages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Xprint multiple pages

    Hi All

    I have been trying to print out multiple pages using XPRINT but the pages overwrite each other and I was able to get only 1 page
    in the output. Is there a NEW page or formfeed command to XPRINT to a new page?

    Here's the code, hope that someone can shine some light of why I did was wrong?

    Code:
    '  Print MEng Sheet.bas
    ' https://forum.powerbasic.com/forum/announcements-articles-and-support-faqs/pbcc-samples/59410-xprint-example-print-an-invoice#post59410
    
    ' Thanks to Gary
    
       ' To print out multiple Engineering calculation sheets
    
    #COMPILE EXE
    #DIM ALL
    
     GLOBAL  hFontBig, hFontSm , hFontSs AS LONG
     GLOBAL  ppiX, ppiY AS LONG
     GLOBAL  CanvasWid, CanvasHt AS SINGLE
     GLOBAL  Xcoord , Ycoord , LefX, TopY, RigX, BotY AS SINGLE
     GLOBAL  rowht, LefBoxVx, RigBoxVx AS SINGLE
     GLOBAL  VLin1x , VLin2x , BotLinY AS SINGLE
     GLOBAL  MarginLeft, MarginRight, MarginTop AS SINGLE
    
    
    
    FUNCTION PBMAIN () AS LONG
          LOCAL FlagXpr AS LONG
          LOCAL ii , NumPg AS LONG
    
          NumPg = 10
    
          ' do not use Times New Roman fonts as it is smaller
          ' and harder to read especially the subscripts
          FONT NEW "Arial", 16, 1 TO hFontBig
          FONT NEW "Arial", 10, 1 TO hFontSm
          FONT NEW "Arial", 8, 1 TO hFontSs
    
          SetupPrint(FlagXpr)
    
          IF FlagXpr = 1 THEN
      '      can proceed to print multiple pages
            FOR ii = 1 TO NumPg
               Prin_Overall( ii)
            NEXT ii
          END IF
    
      '   close all printing
          XPRINT CLOSE
          FONT END hFontBig
          FONT END hFontSm
          FONT END hFontSs
    
    END FUNCTION
    
    
    
    
    ' setup the print canvas and get printer
    ' parameters
    SUB SetupPrint( FlagPrt AS LONG)
        XPRINT ATTACH DEFAULT, "MEng Calc Sheet"
    
        IF ERR OR LEN(XPRINT$) = 0 THEN
            ' on failure
            ? "XPRINT ATTACH failed!"
            EXIT SUB
        END IF
    
        ' Calculate margins
        ' gets the printer resolutions points per inch, PPI
          XPRINT GET PPI TO ppiX, ppiY
    
       ' Gets the NON printable area margins
         XPRINT GET MARGIN TO LefX, TopY, RigX, BotY
    
       ' these margins were tested to print with the
       ' widest possible to accomodate the paper
       ' and binding edges
         MarginLeft  = 0.45 * ppiX - LefX
         MarginRight = 0.3  * ppiX - RigX
         MarginTop   = 0.4  * ppiX - TopY
         FlagPrt = 1
    
    END SUB
    
    
    
    ' Print the overall  Engineering Calculation Sheet type of form
    ' with headers and table for each page
    SUB Prin_Overall( pgn AS LONG)
    
      ' Print the titles
        XPRINT COLOR -1, -1
        XPRINT SET FONT hFontBig
        XPRINT TEXT SIZE "Engineering Calculation Sheet" TO Xcoord, Ycoord
        XPRINT GET CANVAS TO CanvasWid, CanvasHt
        Xcoord = (CanvasWid - Xcoord) / 2      ' centered Xcoord pos
        XPRINT SET POS (Xcoord, MarginTop)
        XPRINT "Engineering Calculation Sheet"
    
        ' Print the table
          XPRINT SET FONT hFontSm
    
          XPRINT WIDTH (0.01 * ppiX)
        ' Line row height for text
          rowht = 0.4 * ppiY
       '  right side of box
          RigBoxVx = CanvasWid - MarginRight
    
    
       ' draw horizontal lines -- Not needed for Engineering Sheet
       ' For Xcoord = 4 To 22
        '    XPrint Line (MarginLeft,  Xcoord * rowht - TopY) - _
        '      (RigBoxVx,  Xcoord * rowht - TopY) , %RGB_MEDIUMSPRINGGREEN
       ' Next
    
      '  Draw only one horizontal line at the top for the column titles
         XPRINT LINE (MarginLeft,  4 * rowht - TopY) - _
               (RigBoxVx,  4 * rowht - TopY) , %RGB_MEDIUMSPRINGGREEN
    
      ' calculate column positions
        LefBoxVx = MarginLeft
      ' first  column vertical line X coordinate
        VLin1x = MarginLeft + (1.2 * ppiX)
      ' second column vertical line X coordinate
        VLin2x = CanvasWid - MarginRight - (1.2 * ppiX)
    
    
    
      ' writes out the column titles
        XPRINT SET POS (MarginLeft + (0.2 * ppiX) ,  4* rowht - TopY - 0.25 * ppiX)
        XPRINT "Reference"
        XPRINT SET POS (MarginLeft + (3.2 * ppiX) ,  4* rowht - TopY - 0.25 * ppiX)
        XPRINT "Calculation"
        XPRINT SET POS (VLin2x + (0.2 * ppiX) ,  4* rowht - TopY - 0.25 * ppiX)
        XPRINT "Output"
    
    
        ' the bottom most horizontal line Y coordinate
          BotLinY = 26.5 * rowht - TopY
    
    
        '  draw a rectangular box around it all and then vertical lines for columns
        '  rgbColor& = -1   if no line color
        '  fillcolor& = -2  no fill color
        '  fillstyle& = 0   no fill style
           XPRINT BOX  (LefBoxVx,  3 * rowht - TopY) - (RigBoxVx, BotLinY), 0, %RGB_MEDIUMSPRINGGREEN , -2, 0
    
       ' draw the vertical column lines
        XPRINT LINE (VLin1x, 3 * rowht - TopY) - (VLin1x, BotLinY) ,%RGB_MEDIUMSPRINGGREEN
        XPRINT LINE (VLin2x, 3 * rowht - TopY) - (VLin2x, BotLinY) , %RGB_MEDIUMSPRINGGREEN
    
       'prints the page number
        XPRINT SET POS (MarginLeft + (3.2 * ppiX) ,  BotLinY + 0.15 * ppiX)
        XPRINT "Page " +STR$(Pgn)
    
    END SUB

  • #2
    XPRINT FORMFEED?

    (Another question that could have been answered in a few seconds by looking at Printing Commands in Help )

    Click image for larger version  Name:	xpff.jpg Views:	0 Size:	48.7 KB ID:	797987

    Comment


    • #3
      Thank you Sir Stuart
      I was only using XPRINT for the first few times and that the list of XPRINT commands are so long

      Comment


      • #4
        Windows printing whether using XPRINT or pure Winapi methods is like using an Etch-a-Sketch.. one page unless you 'do something.'

        Except you can move the stylus without leaving a line.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X