Loading ...
Sorry, an error occurred while loading the content.

Printing with page separation

Expand Messages
  • Jeffrey Huntley
    I am reading a random access file, sorting and formatting the output to a text file for later printing. I need to separate the data by groups and need a page
    Message 1 of 3 , Sep 2, 2003
    • 0 Attachment
      I am reading a random access file, sorting and formatting the output
      to a text file for later printing. I need to separate the data by
      groups and need a page break between. The old chr$(12) form feed does
      not work as in other Basics. Any suggestions as to what LB string I
      can include in the output to force a printer page-break? I output to
      either a Canon BJ or an IBM Laser but this should not be an issue.

      Thanks,

      Jeff
    • Trevor Austin
      ... Try code below .Should do your job Trevor 01093003 Demo Print so as can change font on fly for printing This was taken from a demo program and
      Message 2 of 3 , Sep 3, 2003
      • 0 Attachment
        --- Jeffrey Huntley <barcom@...> wrote:
        > I am reading a random access file, sorting and
        > formatting the output
        > to a text file for later printing. I need to
        > separate the data by
        > groups and need a page break between. The old
        > chr$(12) form feed does
        > not work as in other Basics. Any suggestions as to
        > what LB string I
        > can include in the output to force a printer
        > page-break? I output to
        > either a Canon BJ or an IBM Laser but this should
        > not be an issue.
        >
        > Thanks,
        >
        > Jeff
        >
        >
        Try code below .Should do your job Trevor

        ' 01093003
        ' Demo Print so as can change font on fly for printing
        ' This was taken from a demo program and rearranged a
        bit
        'Use if of any use .Could be improved but does all I
        want
        'Trevor Austin


        nomainwin
        WindowWidth=640:WindowHeight=480
        open "Demo Print Program -------- Freeware "
        for window as #1
        print #1, "trapclose [quit]"


        'printer routine
        setupprinterok = SetupPrinter()
        if setupprinterok then
        HeadingFont = CreateFont("font ms_sans_serif", 20,
        1, 0, 1)' font in points
        NormalFont = CreateFont("Courier New", 12, 0, 0,
        0) 'font in points
        PagenumberFont = CreateFont("font ms_sans_serif",
        35, 1, 0, 0)' font in points
        '*** DRAW PAGE ***
        startNewPage = 1
        linecnt = 1
        page = 1

        for i = 1 to 70
        printY = 0.8+linecnt*12/72
        if printY > 10.5 then ' in inches 10.5"
        for A4 page
        call EjectPage
        startNewPage = 1
        page=page +1
        end if

        if startNewPage then
        startNewPage = 0
        linecnt = 1

        call StartPage

        call SetFont PagenumberFont ' just
        for fun make it big
        call PrintText 6, 10.5, "Page "+
        str$(page)'6inches across 10.5inches down

        call SetFont HeadingFont
        call PrintText 0.3, 0.5,"Place Heading
        Here"

        call DrawLine 0, 0.8, 10, 0.8 '
        inches from top left corner

        call SetFont NormalFont

        printY = 0.8+linecnt*12/72
        end if
        call PrintText 0.3, printY, "middle text"
        linecnt = linecnt + 1

        next i



        call EjectPage

        call DeleteFont HeadingFont
        call DeleteFont NormalFont
        call DeleteFont PagenumberFont

        call FinishPrinting
        end if

        wait
        [quit]
        close #1
        end



        '***************** printing **********************


        function SetupPrinter()
        struct PD,_
        lStructSize as ulong,_
        hwndOwner as long,_
        hDevMode as long,_
        hDevNames as long,_
        hDC as long,_
        Flags as ulong,_
        nFromPage as word,_
        nToPage as word,_
        nMinPage as word,_
        nMaxPage as word,_
        nCopies as word,_
        hInstance as long,_
        lCustData as ulong,_
        lpfnPrintHook as long,_
        lpfnSetupHook as long,_
        lpPrintTemplateName as long,_
        lpSetupTemplateName as long,_
        hPrintTemplate as long,_
        hSetupTemplate as long

        PD.Flags.struct=_PD_RETURNDC
        PD.lStructSize.struct=len(PD.struct)

        calldll #comdlg32, "PrintDlgA",PD as struct, r as
        long

        pDC=PD.hDC.struct

        if pDC > 0 then
        'returns dots per inch width, printer
        calldll #gdi32, "GetDeviceCaps",_
        pDC as long,_
        _LOGPIXELSX as long,_
        dpix as long

        'returns dots per inch height, printer
        calldll #gdi32, "GetDeviceCaps",_
        pDC as long,_
        _LOGPIXELSY as long,_
        dpiy as long

        'this struct is needed for StartDoc
        struct docInfo, _
        cbSize as long,_
        lpszDocName$ as ptr,_
        lpszOutput$ as ptr,_
        lpszDatatype$ as ptr,_
        fwType as ulong

        docInfo.cbSize.struct=len(docInfo.struct)
        docInfo.lpszDocName$.struct="Printer
        Test"+chr$(0)

        'begins the print job
        calldll #gdi32, "StartDocA", _
        pDC as long, _ 'the handle of the printer
        dc
        docInfo as struct, _
        result as long

        SetupPrinter = 1 'Setup ok
        else
        SetupPrinter = 0 'Setup failed
        end if

        PrinterpDC(1) = pDC
        Printerdpix(1) = dpix
        Printerdpiy(1) = dpiy
        End Function
        '**********************************************************
        Sub StartPage
        pDC = PrinterpDC(1)
        'begins a new page
        calldll #gdi32, "StartPage", _
        pDC as long, _ 'the handle of the printer dc
        r as long
        End Sub
        '**********************************************************
        Sub FinishPrinting
        pDC = PrinterpDC(1)

        'end printing session
        calldll #gdi32, "EndDoc", _
        pDC as long,_ 'the handle of the printer dc
        result as long


        'delete printer dc
        calldll #gdi32, "DeleteDC",_
        pDC as long,_ 'the handle of the Printer DC
        result as long 'a return of 0 indicates an
        error
        End Sub
        '**************************************************************
        Sub EjectPage
        'eject page
        pDC = PrinterpDC(1)
        calldll #gdi32, "EndPage", _
        pDC as long,_ 'the handle of the printer dc
        result as long
        End Sub
        '*****************************************************************
        Sub DrawLine orgx, orgy, endx, endy
        pDC = PrinterpDC(1)

        x0 = int(Printerdpix(1) * orgx) 'line will begin 2
        1/2 inches from left
        y0 = int(Printerdpiy(1) * orgy) 'line will begin 4
        inches from top
        x1 = int(Printerdpix(1) * endx) 'line will end on
        right side of page
        y1 = int(Printerdpiy(1) * endy) 'line will end 4
        inches from top

        struct P,x As long, y As long

        calldll #gdi32, "MoveToEx",_
        pDC as long,_ 'handle to the printer's DC
        x0 as long,_ 'starting X coordinate
        y0 as long,_ 'starting Y coordinate
        P as struct,_ 'struct containing old x,y
        result as boolean

        calldll #gdi32, "LineTo",_
        pDC as long,_ 'handle to the printer's DC
        x1 as long,_ 'ending X coordinate
        y1 as long,_ 'ending Y coordinate
        result as boolean 'nonzero is successful


        End Sub
        '**********************************************************
        Sub PrintText x, y, text$

        lengthtext=len(text$)
        textx = int(x * Printerdpix(1))
        texty = int(y * Printerdpiy(1))

        pDC = PrinterpDC(1)

        'send text to printer
        calldll #gdi32, "TextOutA", _
        pDC as long,_ 'device context
        textx as long,_ 'x origin of text
        texty as long,_ 'y origin of text
        text$ as ptr,_ 'text string to display
        lengthtext as long,_'length of text string
        result as long 'nonzero if successful

        End Sub
        '*******************************************************************
        Function CreateFont(fontname$, height, italic,
        underline, bold)
        'set font attributes
        fontheight = int(Printerdpiy(1) * height/72)
        '.25 inch high
        fontwidth = int(Printerdpix(1) * 0.5*(height/72))
        '.15 inch wide
        if bold = 1 then
        fontweight = _FW_BOLD 'bold
        end if

        fontnm$ = fontname$ + chr$(0)

        'create a font
        Calldll #gdi32, "CreateFontA",_
        fontheight as long, fontwidth as long,_
        escapement as long, orientation as long,_
        weight as long, italic as long,_
        underline as long, strikeout as long,_
        CharSet as long, OutputPrecision as long,_
        ClipPrecision as long, Quality as long,_
        PitchAndFamily as long, fontnm$ as PTR,_
        newfont as long

        'print "font handle ";newfont

        CreateFont=newfont
        End Function
        '******************************************************************
        Sub SetFont thefont
        'select font into printer device context
        pDC = PrinterpDC(1)
        Calldll #gdi32, "SelectObject",_
        pDC as long,_ 'handle to the DC
        thefont as long,_ 'handle to the new font
        oldfont as long 'handle to the previous font
        End Sub
        '*****************************************************************
        Sub DeleteFont thefont
        'delete font
        Calldll #gdi32, "DeleteObject",_
        thefont as long,_ 'handle of font to delete
        result as long 'nonzero if successful
        End Sub



        __________________________________
        Do you Yahoo!?
        Yahoo! SiteBuilder - Free, easy-to-use web site design software
        http://sitebuilder.yahoo.com
      • bbjen@hotPOP.com
        Hi Trevor, I couldn t see where anyone has thanked you, so I m writing. That was a very generous bunch of code you offered in answer to Jeffrey s problem. I
        Message 3 of 3 , Sep 13, 2003
        • 0 Attachment
          Hi Trevor,
          I couldn't see where anyone has thanked you, so I'm writing.
          That was a very generous bunch of code you offered in answer to Jeffrey's
          problem. I hope you are as prolific when I have one (... it happens often).

          Bill J.
          ----------------------------------------------------------------

          At 07:55 PM 9/3/2003 -0700, you wrote:
          >
          >--- Jeffrey Huntley <barcom@...> wrote:
          >> I am reading a random access file, sorting and
          >> formatting the output
          >> to a text file for later printing. I need to
          >> separate the data by
          >> groups and need a page break between. The old
          >> chr$(12) form feed does
          >> not work as in other Basics. Any suggestions as to
          >> what LB string I
          >> can include in the output to force a printer
          >> page-break? I output to
          >> either a Canon BJ or an IBM Laser but this should
          >> not be an issue.
          >>
          >> Thanks,
          >>
          >> Jeff
          >>
          >>
          >Try code below .Should do your job Trevor
          >
          >' 01093003
          >' Demo Print so as can change font on fly for printing
          >' This was taken from a demo program and rearranged a
          >bit
          >'Use if of any use .Could be improved but does all I
          >want
          >'Trevor Austin
          >
          >
          > nomainwin
          > WindowWidth=640:WindowHeight=480
          > open "Demo Print Program -------- Freeware "
          >for window as #1
          > print #1, "trapclose [quit]"
          >
          >
          >'printer routine
          >setupprinterok = SetupPrinter()
          >if setupprinterok then
          > HeadingFont = CreateFont("font ms_sans_serif", 20,
          >1, 0, 1)' font in points
          > NormalFont = CreateFont("Courier New", 12, 0, 0,
          >0) 'font in points
          > PagenumberFont = CreateFont("font ms_sans_serif",
          >35, 1, 0, 0)' font in points
          > '*** DRAW PAGE ***
          > startNewPage = 1
          > linecnt = 1
          > page = 1
          >
          > for i = 1 to 70
          > printY = 0.8+linecnt*12/72
          > if printY > 10.5 then ' in inches 10.5"
          >for A4 page
          > call EjectPage
          > startNewPage = 1
          > page=page +1
          > end if
          >
          > if startNewPage then
          > startNewPage = 0
          > linecnt = 1
          >
          > call StartPage
          >
          > call SetFont PagenumberFont ' just
          >for fun make it big
          > call PrintText 6, 10.5, "Page "+
          >str$(page)'6inches across 10.5inches down
          >
          > call SetFont HeadingFont
          > call PrintText 0.3, 0.5,"Place Heading
          >Here"
          >
          > call DrawLine 0, 0.8, 10, 0.8 '
          >inches from top left corner
          >
          > call SetFont NormalFont
          >
          > printY = 0.8+linecnt*12/72
          > end if
          > call PrintText 0.3, printY, "middle text"
          > linecnt = linecnt + 1
          >
          > next i
          >
          >
          >
          > call EjectPage
          >
          > call DeleteFont HeadingFont
          > call DeleteFont NormalFont
          > call DeleteFont PagenumberFont
          >
          > call FinishPrinting
          >end if
          >
          >wait
          >[quit]
          > close #1
          > end
          >
          >
          >
          >'***************** printing **********************
          >
          >
          >function SetupPrinter()
          > struct PD,_
          > lStructSize as ulong,_
          > hwndOwner as long,_
          > hDevMode as long,_
          > hDevNames as long,_
          > hDC as long,_
          > Flags as ulong,_
          > nFromPage as word,_
          > nToPage as word,_
          > nMinPage as word,_
          > nMaxPage as word,_
          > nCopies as word,_
          > hInstance as long,_
          > lCustData as ulong,_
          > lpfnPrintHook as long,_
          > lpfnSetupHook as long,_
          > lpPrintTemplateName as long,_
          > lpSetupTemplateName as long,_
          > hPrintTemplate as long,_
          > hSetupTemplate as long
          >
          > PD.Flags.struct=_PD_RETURNDC
          > PD.lStructSize.struct=len(PD.struct)
          >
          > calldll #comdlg32, "PrintDlgA",PD as struct, r as
          >long
          >
          > pDC=PD.hDC.struct
          >
          > if pDC > 0 then
          > 'returns dots per inch width, printer
          > calldll #gdi32, "GetDeviceCaps",_
          > pDC as long,_
          > _LOGPIXELSX as long,_
          > dpix as long
          >
          > 'returns dots per inch height, printer
          > calldll #gdi32, "GetDeviceCaps",_
          > pDC as long,_
          > _LOGPIXELSY as long,_
          > dpiy as long
          >
          > 'this struct is needed for StartDoc
          > struct docInfo, _
          > cbSize as long,_
          > lpszDocName$ as ptr,_
          > lpszOutput$ as ptr,_
          > lpszDatatype$ as ptr,_
          > fwType as ulong
          >
          > docInfo.cbSize.struct=len(docInfo.struct)
          > docInfo.lpszDocName$.struct="Printer
          >Test"+chr$(0)
          >
          > 'begins the print job
          > calldll #gdi32, "StartDocA", _
          > pDC as long, _ 'the handle of the printer
          >dc
          > docInfo as struct, _
          > result as long
          >
          > SetupPrinter = 1 'Setup ok
          > else
          > SetupPrinter = 0 'Setup failed
          > end if
          >
          > PrinterpDC(1) = pDC
          > Printerdpix(1) = dpix
          > Printerdpiy(1) = dpiy
          >End Function
          >'**********************************************************
          >Sub StartPage
          > pDC = PrinterpDC(1)
          > 'begins a new page
          > calldll #gdi32, "StartPage", _
          > pDC as long, _ 'the handle of the printer dc
          > r as long
          >End Sub
          >'**********************************************************
          >Sub FinishPrinting
          > pDC = PrinterpDC(1)
          >
          > 'end printing session
          > calldll #gdi32, "EndDoc", _
          > pDC as long,_ 'the handle of the printer dc
          > result as long
          >
          >
          > 'delete printer dc
          > calldll #gdi32, "DeleteDC",_
          > pDC as long,_ 'the handle of the Printer DC
          > result as long 'a return of 0 indicates an
          >error
          >End Sub
          >'**************************************************************
          >Sub EjectPage
          > 'eject page
          > pDC = PrinterpDC(1)
          > calldll #gdi32, "EndPage", _
          > pDC as long,_ 'the handle of the printer dc
          > result as long
          >End Sub
          >'*****************************************************************
          >Sub DrawLine orgx, orgy, endx, endy
          > pDC = PrinterpDC(1)
          >
          > x0 = int(Printerdpix(1) * orgx) 'line will begin 2
          >1/2 inches from left
          > y0 = int(Printerdpiy(1) * orgy) 'line will begin 4
          >inches from top
          > x1 = int(Printerdpix(1) * endx) 'line will end on
          >right side of page
          > y1 = int(Printerdpiy(1) * endy) 'line will end 4
          >inches from top
          >
          > struct P,x As long, y As long
          >
          > calldll #gdi32, "MoveToEx",_
          > pDC as long,_ 'handle to the printer's DC
          > x0 as long,_ 'starting X coordinate
          > y0 as long,_ 'starting Y coordinate
          > P as struct,_ 'struct containing old x,y
          > result as boolean
          >
          > calldll #gdi32, "LineTo",_
          > pDC as long,_ 'handle to the printer's DC
          > x1 as long,_ 'ending X coordinate
          > y1 as long,_ 'ending Y coordinate
          > result as boolean 'nonzero is successful
          >
          >
          >End Sub
          >'**********************************************************
          >Sub PrintText x, y, text$
          >
          > lengthtext=len(text$)
          > textx = int(x * Printerdpix(1))
          > texty = int(y * Printerdpiy(1))
          >
          > pDC = PrinterpDC(1)
          >
          > 'send text to printer
          > calldll #gdi32, "TextOutA", _
          > pDC as long,_ 'device context
          > textx as long,_ 'x origin of text
          > texty as long,_ 'y origin of text
          > text$ as ptr,_ 'text string to display
          > lengthtext as long,_'length of text string
          > result as long 'nonzero if successful
          >
          >End Sub
          >'*******************************************************************
          >Function CreateFont(fontname$, height, italic,
          >underline, bold)
          > 'set font attributes
          > fontheight = int(Printerdpiy(1) * height/72)
          >'.25 inch high
          > fontwidth = int(Printerdpix(1) * 0.5*(height/72))
          > '.15 inch wide
          > if bold = 1 then
          > fontweight = _FW_BOLD 'bold
          > end if
          >
          > fontnm$ = fontname$ + chr$(0)
          >
          > 'create a font
          > Calldll #gdi32, "CreateFontA",_
          > fontheight as long, fontwidth as long,_
          > escapement as long, orientation as long,_
          > weight as long, italic as long,_
          > underline as long, strikeout as long,_
          > CharSet as long, OutputPrecision as long,_
          > ClipPrecision as long, Quality as long,_
          > PitchAndFamily as long, fontnm$ as PTR,_
          > newfont as long
          >
          > 'print "font handle ";newfont
          >
          > CreateFont=newfont
          >End Function
          >'******************************************************************
          >Sub SetFont thefont
          > 'select font into printer device context
          > pDC = PrinterpDC(1)
          > Calldll #gdi32, "SelectObject",_
          > pDC as long,_ 'handle to the DC
          > thefont as long,_ 'handle to the new font
          > oldfont as long 'handle to the previous font
          >End Sub
          >'*****************************************************************
          >Sub DeleteFont thefont
          > 'delete font
          > Calldll #gdi32, "DeleteObject",_
          > thefont as long,_ 'handle of font to delete
          > result as long 'nonzero if successful
          >End Sub
          >______________________________
        Your message has been successfully submitted and would be delivered to recipients shortly.