Author Topic: Printing to a USB Printer  (Read 3681 times)

0 Members and 1 Guest are viewing this topic.

Offline Clay Larson

  • Newbie
  • Posts: 2
    • View Profile
Printing to a USB Printer
« on: December 05, 2019, 03:58:27 pm »
Using QB64, is there anyway to control the font printed on a USB printer?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Printing to a USB Printer
« Reply #1 on: December 05, 2019, 05:15:40 pm »
Hi.
Yes. Use _LOADFONT, _FONT, print it to screen (as preview) with white background and then use _PRINTIMAGE for printing this screen to paper. Is possible using virtual (unvisible) screens.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printing to a USB Printer
« Reply #2 on: December 05, 2019, 05:30:10 pm »
I'd probably experiment with _HIDESCREEN to see if your method would still work, and restore the screen after a suitable delay, programmed for the length of the document to be printed.

Another way is to slave it out to Wordpad. Write something in Wordpad in the font style and size you want to print. Save it and open it in Notepad. The .rtf Wordpad file will open and show the font formatting. Now all you have to do is write that formatting info to a file. When you are ready to print from your program, you open that file, input the formatting, and write it to a temporary file followed by the text your program needs to print, and any closing formatting. Save the temporary file and do a SHELL printer command to Wordpad for that file: SHELL _HIDE _DONTWAIT "wordpad /min /p myfile.tmp"

Here is an example I wrote for another forum member: https://www.qb64.org/forum/index.php?topic=979.msg101797#msg101797

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

FellippeHeitor

  • Guest
Re: Printing to a USB Printer
« Reply #3 on: December 05, 2019, 06:14:53 pm »
It’s not a matter of using _HIDESCREEN. The thing is that you can use a new image in memory without having to display it so your program can continue running and you can generate the image to print without showing it.
« Last Edit: December 05, 2019, 06:30:46 pm by FellippeHeitor »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printing to a USB Printer
« Reply #4 on: December 05, 2019, 06:38:08 pm »
That reminds me of PCOPY. Ah, the good ol' days!

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

FellippeHeitor

  • Guest
Re: Printing to a USB Printer
« Reply #5 on: December 05, 2019, 06:49:59 pm »
That reminds me of PCOPY. Ah, the good ol' days!

Pete :)

Same idea indeed ☺️

Offline Clay Larson

  • Newbie
  • Posts: 2
    • View Profile
Re: Printing to a USB Printer
« Reply #6 on: December 05, 2019, 10:28:02 pm »
Thanks for everyone's responses.  From Peter's sample code, I can see how you could control the printed output.  It is a little kludgy.  You'd certainly want to hide this sausage making.  To this end, I couldn't find the _HIDESCREEN procedure.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printing to a USB Printer
« Reply #7 on: December 06, 2019, 05:44:37 am »
My bad. Blame it on old-age dyslexia. Try _SCREENHIDE. Oh, if you try it, remember to redisplay the screen, or end the program with SYSTEM, otherwise the instance of the exe will not terminate, and you'll have to terminate your QB64 exe it with Task Manager. Good luck!

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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Printing to a USB Printer
« Reply #8 on: December 06, 2019, 11:28:27 am »
Better is real source code, instead of general bullshit...

Code: QB64: [Select]
  1. 'printing example
  2. 'A4 paper size is 210x297 mm. So ratio is 1.414258571  Hmmm
  3.  
  4. Ratio = 297 / 210
  5. RAT = 1000
  6.  
  7.  
  8. PaperWidth = RAT
  9. PaperHeight = RAT / Ratio
  10. 'This is for portrait printing. If you want to print landscape, flip it.
  11.  
  12.  
  13. Paper& = _NEWIMAGE(PaperWidth, PaperHeight, 32)
  14. _DEST Paper&
  15. CLS , &HFFFFFFFF 'the same as CLS, _RGBA32(255, 255, 255, 255)    <-create white background for save cartridge
  16. DIM font(14) AS LONG
  17. FOR Sizes = 1 TO 30 STEP 2
  18.     COLOR _RGB32(Sizes * 7, 0, 255 - 7 * Sizes)
  19.     font(i) = _LOADFONT("lbrite.ttf", Sizes, "bold")
  20.     _FONT font(i), Paper&
  21.     _PRINTSTRING (50, 50 + _FONTHEIGHT(font(i)) * i), "This is text printed with Calibri font in size" + STR$(Sizes)
  22.     i = i + 1
  23. NEXT Sizes
  24.  
  25.  
  26.  
  27.  
  28. INPUT "View page before print? [Y/N]"; m$
  29.     CASE "Y": SCREEN Paper&: SLEEP
  30.  
  31. SCREEN 0 'first screen (program is in text mode, but Paper screen is in graphic mode)
  32. INPUT "Press P for print, or other key for end"; m$
  33. IF UCASE$(m$) = "P" THEN _PRINTIMAGE Paper&
  34.  
  35. 'Of course, for printing, it is also necessary to check with _PRINTWIDTH whether the printing is no longer in the X axis outside the printable area.
  36. '_PRINTIMAGE supports color printing, including images.
  37.  
  38.  
  39.  
  40.  
  41. 'erase memory!
  42. _FREEIMAGE Paper& '                 first kill screen contains used fonts,
  43. FOR KillFonts = 0 TO 14 '           then kill used fonts for free memory.
  44.     _FREEFONT font(KillFonts)
  45.  
  46.  
  47.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printing to a USB Printer
« Reply #9 on: December 06, 2019, 12:41:01 pm »
Hey, I'm a navy man. I never post "general" bullshit, only "admirable" bullshit. :D

Well, kidding aside, and yes, I know, the proper spelling is admiral for the navy rank, the routine works as advertised.

One Note: The user might need to include the font path. I use Windows, and I don't keep any fonts in my local QB64 directory, so I changed the _LOADFONT line to: c:\windows\fonts\lucon.ttf and the screen print line from "Calibre" to "Lucinda Console". It printed perfectly.

Nice routine, my friend!

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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Printing to a USB Printer
« Reply #10 on: December 06, 2019, 12:48:58 pm »
Hi Pete,
I meant my first own post :)

Thank you. :)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printing to a USB Printer
« Reply #11 on: December 06, 2019, 01:19:03 pm »
Yes, I know you did. I should have worded it as such, but I just couldn't resist rushing to post that horrible pun. I have to have my sense of humor in this world, because I figure in the next life, laughing at God won't end well...

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