1. Printing using Win32Lib
- Posted by lpuster May 23, 2011
- 2456 views
I am converting an old program that used to print the DOS way. I changed it to use the Win32Lib printing functions. It works when I send plain text, but when I include PCL escape sequences to select fonts, set margins, position text, draw lines, etc. they get modified. It appears that the ESC character is being sent to the printer as a left pointing arrow and everything is overprinting on the first line.
Windows 7 SP1, Euphoria 3.1.1, Win32Lib 0.70.4a, HP LaserJet 4200
2. Re: Printing using Win32Lib
- Posted by zebra May 23, 2011
- 2434 views
I am converting an old program that used to print the DOS way. I changed it to use the Win32Lib printing functions. It works when I send plain text, but when I include PCL escape sequences to select fonts, set margins, position text, draw lines, etc. they get modified. It appears that the ESC character is being sent to the printer as a left pointing arrow and everything is overprinting on the first line.
Windows 7 SP1, Euphoria 3.1.1, Win32Lib 0.70.4a, HP LaserJet 4200
Use API as explained here
3. Re: Printing using Win32Lib
- Posted by lpuster May 23, 2011
- 2425 views
From the title, this sounds like just what I needed. However, I didn't find any of the content useful. It mentions the "Escape" API but: "The Windows API Escape() function is provided in Windows versions 3.0 and 3.1 for backward compatibility with earlier versions of Microsoft Windows." So it's not in Windows 7, and even if it were, I have no syntax information.
It refers to KB138594, which also would seem to be helpful, but the example is in C and depends on an unspecified library. However, I can see the relationship between the example's functions and Win32Lib's functions. This KB also mentions RAWPRN.EXE which contains a program with syntax Rawprint <Printername> <Filename>. Since the printer is network attached, I have no idea what to put for a Printername. Awhile back, I tried to get "Net Use LPT1:
computername\sharename" to work, but I never could find a computername\sharename that would work because the print server is a JetDirect card.
Conclusion: The Win32Lib print functions are very rudimentary and only suitable for plain text.
I was hoping to hear from someone who had actually done it and would provide a sample coded in Euphoria.
4. Re: Printing using Win32Lib
- Posted by DerekParnell (admin) May 23, 2011
- 2374 views
Conclusion: The Win32Lib print functions are very rudimentary and only suitable for plain text.
I was hoping to hear from someone who had actually done it and would provide a sample coded in Euphoria.
Your conclusion is not accurate. Win32lib can be used to do Graphical printing as easy as it can do it to a window.
The trick is to avoid using raw PCL commands and just use standard windows drawing and text/font routines, in conjunction with the Start/End Document/Page commands.
I'm a bit busy right now but I'll get a small sample program written for you over the next day or so.
5. Re: Printing using Win32Lib
- Posted by dcole May 25, 2011
- 2376 views
Hello lpuster,
This code works with Windows 7. I got it from one of the demos.
I don't know about special charaters.
Hope this helps.
Don Cole
include win32lib.ew integer junk, linecount, charsPerLine, linesPerPage sequence fontSize, printerSize, text, lineOfText global constant Window1 = create(Window,"Printer Test",0,10,10,300,210,0) global integer PrWin PrWin=Window1 constant MenuP = create(Menu,"&Printer",PrWin,0,0,0,0,0), info= create(MenuItem,"Get Info", MenuP,0,0,0,0,0), PNow = create(MenuItem,"&A demo page !",MenuP,0,0,0,0,0) --=include printer2.ew --^^^^^^^^^^^^^^^--the window and controls -- a long text line procedure get_info(integer a, integer b, sequence p) -- open the printer dialog -- then, IF the user has selected a printer... if length(getPrinter()) > 0 then -- pick a big fixed width font --setFont( Printer, "Courier New", 24, Normal ) -- get the font metrics setFont(Printer,"Courier New",16,Normal) fontSize = getFontSize( Printer ) -- get the size of a printer page printerSize = getCtlSize( Printer ) -- how many characters can fit on a line? charsPerLine = floor(printerSize[1]/fontSize[1]) -- how many lines can fit on a page? linesPerPage = floor(printerSize[2]/fontSize[2]) -- report all the printer's 'metrics' --setText(FONT,"Curier New") --setText(FONT_SIZE,"16") --setText(FONT_STYLE,"Normal") --setText(PRINTER_WIDTH,printerSize[1]) --setText(PRINTER_HEIGHT,printerSize[2]) --setText(PRT_CHRW,fontSize[1]) --setText(PRT_CHRH,fontSize[2]) --setText(PRT_CHR_PER,charsPerLine) --setText(PRT_LINES_PER,linesPerPage) end if --setEnable(PRINT_BTN,w32False) --o--penWindow(PREVIEW,Normal) end procedure setHandler(info,w32HClick,routine_id("get_info")) procedure print_now(integer a,integer b,sequence p) -- closeWindow(PREVIEW) -- start up the document if startDoc( "My Print Job" ) then junk = startPage() -- top of page linecount = 0 ----------------------------------put your printing here------------------ for x= 1 to 45 do setPenPos(Printer,0,linecount*fontSize[2]) wPuts( Printer,sprintf("%d",x) ) -- move down one line linecount += 1 -- at bottom of page? if linecount > linesPerPage then -- print page if not endPage() then exit end if -- start a new page if not startPage() then exit end if -- reset counter linecount = 0 end if end for ------------------------------------------------------------------------------- -- then, finally, send the page to the printer junk=endPage() -- so, this ends our 'shucks' graphics demonstration. end if -- end of document if endDoc() then -- release the printer releasePrinter() end if end procedure -- setHandler(PNow,w32HClick,{routine_id("get_info"),routine_id("print_now")}) --setHandler(PNow,w32HClick,routine_id("print_now")) --onClick[PNow] = routine_id("print_now") WinMain(PrWin,Normal)
6. Re: Printing using Win32Lib
- Posted by Selgor May 25, 2011
- 2319 views
Selgor here Don...... Which Demo did you get "it" .. the proggie from ?? Read You to-morrow.
Cheers, Selgor.
7. Re: Printing using Win32Lib
- Posted by FredRansom May 26, 2011
- 2290 views
See my calendar program. It contains a section for printing. This section mixes text and simple drawing methods. Also, use C type escape characters, not escape sequences. For example, use '\n', not {27, 'n'}. Part of the program uses EU4, but the printing routines use EU3. It uses win32lib.
8. Re: Printing using Win32Lib
- Posted by dcole May 27, 2011
- 2305 views
Selgor here Don...... Which Demo did you get "it" .. the proggie from ?? Read You to-morrow.
Cheers, Selgor.
Hello Signor,
I found it in an old folder in the archives called euWinTutor.
I don't see it there anymore. This is probably because it uses onClick (no longer used).
It must be changed setHandler as I did in my last post in this thread.
There are 2 files pr123.exw,
-- pr123.exw by Wolf. include win32lib.ew include printws.ew without warning -- create the window and menu. constant MenuWin = create(Window,"Print Demo",0,Default,Default,340,130,0), PopupFile = create(Menu,"&File",MenuWin,0,0,0,0,0), MenuPrint = create(MenuItem,"&Print",PopupFile,0,0,0,0,0), MenuSep1 = create(MenuItem,"-",PopupFile,0,0,0,0,0), MenuExit = create(MenuItem,"E&xit",PopupFile,0,0,0,0,0), PopupHelp = create(Menu,"&Help",MenuWin,0,0,0,0,0), MenuAbout = create(MenuItem,"&About",PopupHelp,0,0,0,0,0), Dummy = create(Menu," -prints 3 pages thru FILE,PRINT-",MenuWin,0,0,0,0,0) setFont( MenuWin,"Courier New",10,1) procedure onMenu_MenuAbout() integer result result = message_box("Win32Lib Print Demo, prints itself !", "HELLO !",#2000) end procedure onClick[MenuAbout] = routine_id("onMenu_MenuAbout") integer Handle object line procedure print_stuff(sequence a) --a is filename atom myphdc, i, j, charheight, width, hor, ver sequence mypr, textinfo, string1 mypr=DefaultPrinterName() myphdc=GetPrinterDC(mypr) textinfo=GetTextMetrics(myphdc) charheight=textinfo[1]+1 --character height+1, <this is optional --using textinfo[1] only, allows characters to "touch" --might be useful for DOS'like graphics width=textinfo[2] --character width hor=GetDeviceCaps(myphdc,8) --page width ver=GetDeviceCaps(myphdc,10) --page length setPenPos(MenuWin,0,1) string1= " character height = " & sprintf("%d",textinfo[1]) & " + 1 extra" wPuts(MenuWin,string1) setPenPos(MenuWin,0,18) string1= " character width = " & sprintf("%d",width) wPuts(MenuWin,string1) setPenPos(MenuWin,0,36) string1= " total page height = " & sprintf("%d",ver) wPuts(MenuWin,string1) setPenPos(MenuWin,0,54) string1= " total page width = " & sprintf("%d",hor) wPuts(MenuWin,string1) i=StartDoc(myphdc, a ) --a bit of fooling around... i=StartPage(myphdc) pTextOut(myphdc,150,70,"An Example") pTextOut(myphdc,400,140,"of placing stuff") pTextOut(myphdc,20*width,400,"wherever") pTextOut(myphdc,28*width,408," you want..") pTextOut(myphdc,10*width,400+4*charheight,"within the page extents.") pTextOut(myphdc,floor(hor/2-(8*width)),floor(ver/2-(charheight/2)), "near the middle.") pTextOut(myphdc,50,floor(ver-(8*charheight)),"end of page one.") i=EndPage(myphdc) --end of fooling... i=StartPage(myphdc) Handle=open( a ,"r") j=charheight*4 --some empty space while 1 do line=gets(Handle) if atom(line) then exit end if line=line[1..(length(line)-1)] --remove line feed. --max. char. per line ?? --so do parsing here, using "hor/width=maxx" --or the end of your line will "disappear" if j > ver-charheight*8 then --close to bottom? i=EndPage(myphdc) i=StartPage(myphdc) --next page j=charheight*4 --reset line count end if --careful here, I think this only likes integers. pTextOut(myphdc,0,j,line ) j=j+charheight --increment line count end while close(Handle) i=EndPage(myphdc) --eject page i=EndDoc(myphdc) --and close DeleteDC(myphdc) end procedure procedure onMenu_MenuExit() closeWindow(MenuWin) end procedure onClick[MenuExit] = routine_id("onMenu_MenuExit") procedure onMenu_MenuPrint() print_stuff("pr123.exw") --if it ain't there,CRASH. end procedure onClick[MenuPrint] = routine_id("onMenu_MenuPrint") WinMain(MenuWin,Normal) ----
and pr234.exw
include win32lib.ew integer junk, linecount, charsPerLine, linesPerPage, halfx, halfy sequence fontSize, printerSize, text, lineOfText constant PrWin = create(Window,"Another Win32lib 'print'",0,10,10,300,210,0), MenuP = create(Menu,"&Print",PrWin,0,0,0,0,0), PNow = create(MenuItem,"&A demo page !",MenuP,0,0,0,0,0) -- a long text line text = "I have been working on this tutorial since October of 1998, " & "starting with Win32lib version 0.15c, " & "and even though David added some 'wrappers' to Win32lib.ew for " & "printing " & "quite some time ago, " & "( in version 0.43e, Oct./99 ), it has taken me this long to finally " & "get around to using *his* functions " & "in a tutorial example !" procedure get_info() -- open the printer dialog -- then, IF the user has selected a printer... if length(getPrinter()) > 0 then -- pick a big fixed width font setFont( Printer, "Courier New", 24, Normal ) -- get the font metrics fontSize = getFontSize( Printer ) -- get the size of a printer page printerSize = getCtlSize( Printer ) -- how many characters can fit on a line? charsPerLine = floor(printerSize[1]/fontSize[1]) -- how many lines can fit on a page? linesPerPage = floor(printerSize[2]/fontSize[2]) -- report all the printer's 'metrics' setPenPos(PrWin,10,10) wPuts(PrWin,"...using the \"Courier New\", size 24 font.") setPenPos(PrWin,10,30) wPuts(PrWin,"character width = " & sprintf("%d",fontSize[1])) setPenPos(PrWin,10,50) wPuts(PrWin,"character height = " & sprintf("%d",fontSize[2])) setPenPos(PrWin,10,70) wPuts(PrWin,"characters per line = " & sprintf("%d",charsPerLine)) setPenPos(PrWin,10,90) wPuts(PrWin,"lines per page = " & sprintf("%d",linesPerPage)) setPenPos(PrWin,10,120) wPuts(PrWin,"page 'pixel' width = " & sprintf("%d",printerSize[1])) setPenPos(PrWin,10,140) wPuts(PrWin,"page 'pixel' height = " & sprintf("%d",printerSize[2])) end if end procedure procedure print_now() get_info() -- start up the document if startDoc( "My Print Job" ) then junk = startPage() -- top of page linecount = 0 -- print until long text line is empty while length( text ) do -- get a line of text if length( text ) < charsPerLine then -- get remaining text lineOfText = text text = "" else -- get one 'printer line' of text lineOfText = text[1..charsPerLine] -- remove from remaining text text = text[charsPerLine+1..length(text)] -- is first character of line a space ? if equal(lineOfText[1], ' ') then lineOfText = lineOfText[2..length(lineOfText)] if length(text) > 0 then lineOfText = lineOfText & text[1] end if if length(text) > 1 then text = text[2..length(text)] end if end if end if -- position text on page setPenPos( Printer, 0, linecount*fontSize[2] ) -- write the text wPuts( Printer,lineOfText ) -- move down one line linecount += 1 -- at bottom of page? if linecount > linesPerPage then -- print page if not endPage() then exit end if -- start a new page if not startPage() then exit end if -- reset counter linecount = 0 end if end while -- shucks, we know we haven't printed a full page yet... -- so let's throw in some graphics, OK ? -- draw a fat line half-way down the page. halfy = floor(printerSize[2] / 2) setPenWidth(Printer,5) drawLine(Printer,0,halfy,printerSize[1],halfy) -- draw a fat line at the bottom of the page. setPenWidth(Printer,5) drawLine(Printer,0,printerSize[2]-5,printerSize[1],printerSize[2]-10) -- then draw a circle of size 50, at 20 by 20 below the top line. setPenWidth( Printer,1 ) drawEllipse( Printer, True, -- fill the circle 20, halfy + 25, -- start x,y 20 + 50, halfy + 25 + 50 ) -- end x,y -- then add a line of smaller text after the circle. setFont( Printer, "Courier New", 16, Bold ) setPenPos( Printer, 100, halfy + 25 ) wPuts( Printer, "This makes a BIG point !" ) -- then add a big empty circle with a '400' diameter. halfx = floor(printerSize[1] / 2) setPenWidth( Printer, 4 ) drawEllipse( Printer, False, -- don't fill the circle. halfx - 200, halfy + 100, -- start x,y halfx + 200, halfy + 100 + 400 ) -- end x,y -- with a check-mark near the center. setPenWidth( Printer, 8 ) drawLine( Printer, halfx-50, halfy+300, halfx, halfy+405 ) setPenWidth( Printer, 12 ) drawArc( Printer, False, halfx, halfy+405-600, halfx+600, halfy+405+600, halfx+200, halfy-100, halfx, halfy+400) -- then, finally, send the page to the printer junk=endPage() -- so, this ends our 'shucks' graphics demonstration. end if -- end of document if endDoc() then -- release the printer releasePrinter() end if end procedure setHandler(PNow onClick[PNow] = routine_id("print_now")--this has to e changed here as I did in my last post that sent WinMain(PrWin,Normal)
They won't work with out some work.
Don Cole
9. Re: Printing using Win32Lib
- Posted by Selgor May 27, 2011
- 2229 views
Hello Don............. Selgor here. A lot to be gained from old tutes. I had several tute files. Lost the lot in a "sys crash". I now backup daily . And hence my question. Thanks Don . Cheers, Selgor.
10. Re: Printing using Win32Lib
- Posted by DanM May 27, 2011
- 2378 views
Don,
pr123.exw by Wolf includes printws.ew; what/where's printws.ew?
Dan
11. Re: Printing using Win32Lib
- Posted by Vinoba May 27, 2011
- 2186 views
Don,
pr123.exw by Wolf includes printws.ew; what/where's printws.ew?
Dan
I have the files pr123.exw and printws.ew. I am trying to put them somewhere for you to access. Will post the url as soon as I have done that
12. Re: Printing using Win32Lib
- Posted by Vinoba May 27, 2011
- 2202 views
I have uploaded it to box.net.
http://www.box.net/shared/9kvii9f2rl
Unzip it. the files are in the demo folder.
Best of luck.
13. Re: Printing using Win32Lib
- Posted by dcole May 27, 2011
- 2190 views
I have uploaded it to box.net.
http://www.box.net/shared/9kvii9f2rl
Unzip it. the files are in the demo folder.
Best of luck.
Thank you Vinoba,
I too have this file on my computer but it is too lengthy to post on this forum. Robert Craig created a link on the Euphoria Web Page for uploading temporary files to share like picures etc.. I was desperately looking for it. But couldn't find it. If anybody remembers what it was please post it here.
I don't know why all interest in this file. I repeat it will not work on any current version of euphoria. I just posted it for study purposes.
Don Cole
14. Re: Printing using Win32Lib
- Posted by AndyDrummond May 29, 2011
- 2086 views
If you are interested, I put a library in the contribs years back (2005) called GrPrint. It uses Win32Lib, but it automatically gets the printer characteristics and scales so you can draw lines, shapes, text, anything really. Specify positions and dimensions in inches, millimeters, centimeters or percentages. There is a comprehensive demo in the library file. I use it for all - ALL - my printing, and it just does what it says on the tin. Makes life VERY easy compared to doing things the hard way. Personal opinion, of course, but there you go. Have a look & try it. It was done when Eu 3.0 was the flavour of the month, so you might need to edit it a tad to run under Eu4. I am old fashioned and still use Eu 3 because that also does what it says on the tin!
Andy