Author Topic: Anyone using LPRINT in QB64?  (Read 6176 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Anyone using LPRINT in QB64?
« on: January 26, 2021, 11:59:11 am »
In QuickBASIC, I used either a SHELL to Wordpad or LPRINT in conjunction with printer escape codes to control just about everything, margins, spacing, fonts, etc. The Wiki indicates we lost printer escape codes from CHR$(27) and up, so I'll assume LPRINT CHR$(12) can still be used eject the paper. That's essential. So I guess my question is for those who use LPRINT, were there any workarounds you needed to make printing with it suitable to your needs?

In terms of slave printing, I've used SHELL to Wordpad. Why Wordpad instead of Notepad? because you can make yourself a nice little changeable .rtf template to encase your text file in, and then achieve all the margin, font size, font color, spacing, etc., you desire.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #1 on: January 27, 2021, 06:29:00 am »
I have used it a lot. I have many clients who have dot-matrix printers to print invoices.
Those who have switched to the QB64 program have had to buy laser printers.
Now a client has asked me to also connect a ticket printer and I'm testing it via serial port because sending an image via USB, as with _PRINTIMAGE to make a ticket, can be quite complicated, especially considering that the ticket can be very short, with one article, or very long, with 50 or 60 articles.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #2 on: January 27, 2021, 11:02:05 am »
Thanks, that's what I wanted to know. I miss the old days of extensively using printer escape codes, but I can always fall back to better formatting using my Wordpad .rtf template method. If that would ever come in handy for you, the steps involved are...

1) Open Wordpad and make a doc formatted the way you want your QB64 doc to appear as.
2) Save the Wordpad doc, and then open it in Notepad. Notepad will include the .rtf formatting with the text.
3) Strip out the .rtf formatting parts of the header and footer. I think they are all enclosed in {} brackets, if memory serves. Now make both the header and footer formatting text into two separate template files like WP_header.dat and WP_footer.dat

Now when you make a QB64 doc, make a temp file then open the header template file, input in all the header info. Now input all the QB64 doc text. Finally open the footer template file, and input the footer info. So let's say you named that temp file qb64doc.tmp, you just do a simple SHELL to slave print it in Wordpad...

SHELL _dontwait "START /min /p wordpad qb64doc.tmp"

If my memory isn't faulty, this routine should cause a minimized Wordpad icon to appear in your task bar, and the nicely formatted printing process will occur in the background.

Anyway, you probably don't need this, or already know this and a few other tricks, but if you or anyone else ever need to make use of it, it's here now.

Again, thanks for your reply, much appreciated and good luck with the ticket printing project.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline JohnUKresults

  • Newbie
  • Posts: 40
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #3 on: February 11, 2021, 07:55:24 am »
Hi

Thanks for the reminder of wordpad switches, which I'll include in my QB64 program.

Is there any additional switch, or maybe a QB64 command, which would run this "silently" i.e. just to print without bringing Wordpad up on screen?

Also, is there a switch which might instruct how many copies to print? Don't want to have to run the switch command in a loop (say) 20 times to print 20 copies.

Not a problem if it's not possible. I can always go into the rtf doc and print multiple copies via Windows - would just be handy to be able to send this command at the initial print instruction.

Thanks in advance.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Anyone using LPRINT in QB64?
« Reply #4 on: February 11, 2021, 08:20:52 am »
I do not use LPRINT. I open a TCP/IP connection to the printer over port 9100 and send PCL commands and plain text. Works great for printing formatted documents when one learns some of the PCL language.
Shuwatch!

Offline JohnUKresults

  • Newbie
  • Posts: 40
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #5 on: February 11, 2021, 11:41:45 am »
I don't use LPRINT any more either. I can generate a perfect rtf file in my QB64 program for printing - just after a short cut to print multiple copies, which was easy back in the days of QuickBasic by just sending the right sequence of escape codes to the printer! Don't want to start learning PCL at my age ... :-)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Anyone using LPRINT in QB64?
« Reply #6 on: February 11, 2021, 11:50:36 am »
Am I the only oddball who uses _PRINTIMAGE?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #7 on: February 11, 2021, 12:06:12 pm »
@SpriggsySpriggs That's good to know, but new tricks and old dogs don't play well together. Case in point, I'd reply to you as Nathan, but I'm not altogether certain I have that right. Even worse, I left my pudding out last night, and it melted. :( Thanks for the alternative though, I'll have a look and see if PCL is anything that speaks to me, like my pine tree started doing last year. I'd appreciate those conversations more, if it didn't needle me so much.

Hey John, welcome to the forum. I was happy to see you also use that .rtf work around I discussed in my original post. Good old tricks from the QB days! You probably figured that one out on your own too. Thinking up workarounds was a good deal of the fun in programming. Remember when some coders would dis QB for things (it)... meaning they, couldn't do? Us die hards always found a way. QB64 is a testament to that; otherwise, we'd all be talking FreeBASIC. Well, those of us who failed to commit Seppuku.

Steve, I forgot abut that one. Now I'm trying to remember what I did back in QB days for signatures. I recall some bitmap or gif thing I was able to send to the printer. I know I created something like that, so I'm not losing my mind... but I do misplace it often. Oh, there it is, in the fridge. That's why my pudding didn't get put back!

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Anyone using LPRINT in QB64?
« Reply #8 on: February 11, 2021, 12:09:07 pm »
@Pete

I have lost the template I used for this but this was code I had used at my last job (Grabbed from someone else on the forum for printing documents, can't remember who) that creates an AIAG standard label and uses a barcode font. I draw everything on the image and then print it out. Maybe this can be of assistance?

Code: QB64: [Select]
  1. Dim Shared PageScale
  2. Dim Shared PageHeight
  3. Dim Shared PageWidth
  4. _Title "AIAG Label Maker"
  5. PageScale = 10
  6. PageHeight = 101.6 * PageScale '4" x 6.5" AIAG Label Size
  7. PageWidth = 152.4 * PageScale
  8. 'Page& = _NEWIMAGE(PageWidth, PageHeight, 32)
  9. Page& = _LoadImage("imageoutput.bmp", 32)
  10. '_DEST Page&: CLS , _RGB(255, 255, 255): _DEST 0 'make background white to save ink!
  11. Dim Shared CursorPosY
  12. CursorPosY = 0
  13. 'INPUT "PART NUMBER: ", part$
  14. 'INPUT "QUANTITY   : ", quantity$
  15. 'INPUT "PO NUMBER  : ", po$
  16. 'INPUT "REV NUMBER : ", revision$
  17. 'INPUT "SERIAL NUM : ", serial$
  18. 'INPUT "DESCRIPTION: ", description$
  19. 'INPUT "VENDOR CODE: ", vendor$
  20.  
  21. 'PrintTextBold Page&, 12, " PART #"
  22. 'PrintTextBold Page&, 12, " CUST (P)"
  23. 'PrintTextBold Page&, 12, ""
  24. 'PrintTextBold Page&, 12, ""
  25. 'PrintTextBold Page&, 12, "                                  QUANTITY"
  26. 'PrintTextBold Page&, 12, "                                  (Q)"
  27. 'PrintTextBold Page&, 12, ""
  28. 'PrintTextBold Page&, 12, " PO # (K)                         REV # (ENG #) (2P)"
  29. 'PrintTextBold Page&, 12, ""
  30. 'PrintTextBold Page&, 12, ""
  31. 'PrintTextBold Page&, 12, ""
  32. 'PrintTextBold Page&, 12, ""
  33. 'PrintTextBold Page&, 12, " SERIAL #                         PART DESCRIPTION"
  34. 'PrintTextBold Page&, 12, " MASTER (4S)"
  35. 'PrintTextBold Page&, 12, ""
  36. 'PrintTextBold Page&, 12, ""
  37. 'PrintTextBold Page&, 12, ""
  38. 'PrintTextBold Page&, 12, ""
  39. 'PrintTextBold Page&, 12, "                                  VENDOR #(SUPPLIER ID)(V)"
  40. 'PrintTextBold Page&, 30, " MASTER LABEL"
  41.  
  42. 'SCREEN Page&
  43. Prev& = _NewImage(650, 400, 32) 'print preview
  44. _PutImage , Page&, Prev&
  45. Screen Prev&
  46.  
  47. Input "Save Label (Y/N)?", i$ 'show print preview
  48. If UCase$(i$) = "Y" Then
  49.     SaveImage Page&, "imageoutput2.bmp"
  50. Input "Print Label (Y/N)?", i$ 'print screen page on printer
  51. If UCase$(i$) = "Y" Or UCase$(i$) = "P" Then
  52.     _PrintImage Page&
  53.  
  54.  
  55.  
  56. Sub PrintText (Page&, PointSize, text$)
  57.     FontHeight = Int(PointSize * 0.3527 * PageScale)
  58.     FontHandle = _LoadFont("c:\windows\fonts\monos.ttf", FontHeight)
  59.     _Dest Page&
  60.     _Font FontHandle
  61.     Color _RGB(0, 0, 0), _RGBA(0, 0, 0, 0) 'black text on clear background
  62.     _PrintString (0, CursorPosY), text$
  63.     _Font 16 'change to the QB64 default font to free it
  64.     _FreeFont FontHandle
  65.     _Dest 0
  66.     CursorPosY = CursorPosY + FontHeight 'adjust print position down
  67.  
  68. Sub PrintBarcode (Page&, PointSize, text$)
  69.     FontHeight = Int(PointSize * 0.3527 * PageScale)
  70.     'FontHandle = _LOADFONT("c:\windows\fonts\idautomationhc39m free version.ttf", FontHeight)
  71.     FontHandle = _LoadFont("c:\windows\fonts\archon code 39 barcode.ttf", FontHeight)
  72.     'FontHandle = _LOADFONT("c:\windows\fonts\code39azalea.ttf", FontHeight)
  73.     'FontHandle = _LOADFONT("c:\windows\fonts\free3of9.ttf", FontHeight)
  74.     'FontHandle = _LOADFONT("c:\windows\fonts\connectcode39_s3.ttf", FontHeight)
  75.     _Dest Page&
  76.     _Font FontHandle
  77.     Color _RGB(0, 0, 0), _RGBA(0, 0, 0, 0) 'black text on clear background
  78.     _PrintString (0, CursorPosY), text$
  79.     _Font 16 'change to the QB64 default font to free it
  80.     _FreeFont FontHandle
  81.     _Dest 0
  82.     CursorPosY = CursorPosY + FontHeight 'adjust print position down
  83.  
  84. Sub PrintTextBold (Page&, PointSize, text$)
  85.     FontHeight = Int(PointSize * 0.3527 * PageScale)
  86.     FontHandle = _LoadFont("c:\windows\fonts\monosb.ttf", FontHeight)
  87.     _Dest Page&
  88.     _Font FontHandle
  89.     Color _RGB(0, 0, 0), _RGBA(0, 0, 0, 0) 'black text on clear background
  90.     _PrintString (0, CursorPosY), text$
  91.     _Font 16 'change to the QB64 default font to free it
  92.     _FreeFont FontHandle
  93.     _Dest 0
  94.     CursorPosY = CursorPosY + FontHeight 'adjust print position down
  95.  
  96.  
  97. Sub SaveImage (image As Long, filename As String)
  98.     bytesperpixel& = _PixelSize(image&)
  99.     If bytesperpixel& = 0 Then Print "Text modes unsupported!": End
  100.     If bytesperpixel& = 1 Then bpp& = 8 Else bpp& = 24
  101.     x& = _Width(image&)
  102.     y& = _Height(image&)
  103.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + String$(16, 0) 'partial BMP header info(???? to be filled later)
  104.     If bytesperpixel& = 1 Then
  105.         For c& = 0 To 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  106.             cv& = _PaletteColor(c&, image&) ' color attribute to read.
  107.             b$ = b$ + Chr$(_Blue32(cv&)) + Chr$(_Green32(cv&)) + Chr$(_Red32(cv&)) + Chr$(0) 'spacer byte
  108.         Next
  109.     End If
  110.     Mid$(b$, 11, 4) = MKL$(Len(b$)) ' image pixel data offset(BMP header)
  111.     lastsource& = _Source
  112.     _Source image&
  113.     If ((x& * 3) Mod 4) Then padder$ = String$(4 - ((x& * 3) Mod 4), 0)
  114.     For py& = y& - 1 To 0 Step -1 ' read JPG image pixel color data
  115.         r$ = ""
  116.         For px& = 0 To x& - 1
  117.             c& = Point(px&, py&) 'POINT 32 bit values are large LONG values
  118.             If bytesperpixel& = 1 Then r$ = r$ + Chr$(c&) Else r$ = r$ + Left$(MKL$(c&), 3)
  119.         Next px&
  120.         d$ = d$ + r$ + padder$
  121.     Next py&
  122.     _Source lastsource&
  123.     Mid$(b$, 35, 4) = MKL$(Len(d$)) ' image size(BMP header)
  124.     b$ = b$ + d$ ' total file data bytes to create file
  125.     Mid$(b$, 3, 4) = MKL$(Len(b$)) ' size of data file(BMP header)
  126.     If LCase$(Right$(filename$, 4)) <> ".bmp" Then ext$ = ".bmp"
  127.     f& = FreeFile
  128.     Open filename$ + ext$ For Output As #f&: Close #f& ' erases an existing file
  129.     Open filename$ + ext$ For Binary As #f&
  130.     Put #f&, , b$
  131.     Close #f&
Shuwatch!

Offline JohnUKresults

  • Newbie
  • Posts: 40
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #9 on: February 11, 2021, 12:27:11 pm »
Thanks Pete and Steve.

I don't use _PRINTIMAGE as I am not printing what's on my screen, just text pulled from relational databases for background printing whilst I get on with more data inputting (I compile results for running races etc. so need to able to continue data entry on a different screen whilst pages are starting to print out)

Pete, yes I'd already got that rtf stuff set up but it would only open and write the document, not print it. It was only when looking at your example that I realised I didn't have the space after the /p switch and before my file name started, so that's why it wasn't printing. I'd never have noticed that without your example code! The smallest things eh?

Cheers

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #10 on: February 11, 2021, 12:47:51 pm »
@Pete

I have lost the template I used for this but this was code I had used at my last job (Grabbed from someone else on the forum for printing documents, can't remember who) that creates an AIAG standard label and uses a barcode font. I draw everything on the image and then print it out. Maybe this can be of assistance?
...

Nice! I would have been happy if you just posted your first name. :) I mean call me crazy, but no one I know around the Fort Wayne area would name their kid Spriggsy. Hollywood, closer to where I live, maybe. I really miss the Mid-West some days. Oh wait, pudding be damned! It's Zach. Dust the attic out once in awhile, and behold, the cobwebs do come off! Nathan was Computer Ghost, from the old QB forum, who was about your age when he was posting there, in early 2000 something.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #11 on: February 11, 2021, 01:05:43 pm »
@JohnUKresults

Some of that missing the little things stuff in command prompts used to drive me bit shat crazy back in the 1990's. Those were the good old days when laptops were made of metal, and you could pull out the dents. Today, the darn things just crack!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Anyone using LPRINT in QB64?
« Reply #12 on: February 11, 2021, 01:09:29 pm »
@Pete
Yep, my first name is Zachary. Last name is Spriggs. My high school nickname was Spriggsy. So, I've stuck with that.
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #13 on: February 11, 2021, 01:27:33 pm »
My high school nickname was..., was... Hmm, I can't seem to get it typed past the forum filters. Oh well. Hey, congrats on completing the pipecom thingy. I assume that can be used to generate a list of directory files? I have a really good working one of those with SHELL, but it does have a little more lag than I'd like. Not bad, but just not quite as fast as Notepad. When I get a stable version together, I may try substituting some alternative directory find and printing methods.

It's impressive, to me, that pipecom is cross platform to Windows, Mac, and Linux. SHELL will work on Linux, but I'd bet dollars to donuts there would have to be some differences in parsing the the temp files. Anyway, since I only have Windows systems, I only build for what I can test, Windows. Of course if a system is truly universal, then that's not an issue, so congrats, again.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Anyone using LPRINT in QB64?
« Reply #14 on: February 11, 2021, 02:06:44 pm »
@Pete

Yeah! It existed only as a header library for months but people didn't really understand it. What it does is behave like SHELL but it returns the output of the command to the string rather than needing to make temp files. As it stands, it's faster than using SHELL and temp files and requires less work. As a header, I received complaints and confusing questions. I think that with converting it to purely QB64 code will help alleviate some of that and make it more approachable. Give it a try! You can run the example code I have in the best answer of that thread.
Shuwatch!