fox
Junior Member
Posts: 66
|
Post by fox on Apr 2, 2019 2:05:12 GMT -5
Hi all, I would like to know the simplest way to create a "form feed" for printer with LB Pro v4.5.1. If chr$(10) creates a "line feed" what may be the value of chr$() for a "form feed"? Or there is another way to do it? Thanks a lot to all and bye. fox
|
|
|
Post by Rod on Apr 2, 2019 3:10:31 GMT -5
Modern print drivers do not allow direct control. If you are using LPRINT then keep track of the number of lines. Once you know how many lines fill a page you can add blank lines to force a form feed when needed, or just use DUMP to force lines to be printed. You gain much more control by drawing and printing text in a graphicbox. There is a printform.bas demo that ships with Liberty.
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 2, 2019 4:45:54 GMT -5
Thanks a lot, Rod. I imagined a solution similar to that you suggest (your solution is better), but I thought perhaps there is a more simple way. Thanks a lot again and bye fox
|
|
Jack Kelly
New Member
I see no benefit from anonymity.
Posts: 8
|
Post by Jack Kelly on Apr 2, 2019 19:18:36 GMT -5
Try
lprint chr$(12)
It may work well enough for you.
|
|
|
Post by Rod on Apr 3, 2019 1:29:18 GMT -5
Yes, but would it not need to be as an Escape sequence? So chrs$(27)+chr$(12). I have not seen a directly driven printer for fifteen years or so, the days of simplicity!
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 3, 2019 4:27:27 GMT -5
Thanks a lot, Jack and Rod. But, sorry, I'm not able to put into practice your suggestion. Please, can you post a little (code) example? Thanks a lot again and bye. fox
|
|
|
Post by mknarr on Apr 3, 2019 10:28:27 GMT -5
I don't know I may be all wet but lprint "dummy" dump lprint "dummy2" dump
Will print the first line on one page, go to the next page and print the second line.
If you are talking about printing an unknown number of lines that will span more than one page, the printer will automatically go to the next page.
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 3, 2019 12:02:22 GMT -5
Thanks a lot, mknarr. My idea is to insert at top of all new page 5 titles for 5 different columns of data. I know that every dump creates a "form feed". So I think I can calculate how many lines I want for every page and insert a dump when the lines are enough. But I was thinking also if there is a way (with some other "form feed" method) to force printer to print double-side (the same page). Thanks a lot again and bye. fox
|
|
|
Post by mknarr on Apr 4, 2019 9:45:44 GMT -5
I found this code but have no idea who wrote it.
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 to 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="PrinterTest"+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 4inches 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
|
|
fox
Junior Member
Posts: 66
|
Post by fox on Apr 4, 2019 15:17:33 GMT -5
A very interesting code. I will study it accurately. Thanks a lot, mknarr and bye. fox
|
|