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

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #15 on: February 16, 2021, 04:33:16 am »
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

Hi ,
I use _PRINTIMAGE to list the data obtained from the database but it is very slow, especially if I want to convert it to pdf with the PDFCreator.
I'm very interested to know how you do background printing with rtf file.
Could you give me an example of how to create the rtf file and print it in the background?
I don't know how to create an .rtf file with the data that I want to print.
Thanks

« Last Edit: February 16, 2021, 05:03:44 am by Juanjogomez »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #16 on: February 17, 2021, 12:16:08 pm »
Wow, it's been 15 yers since I worked with this, so...

The way I learned was by opening wordpad, typing out something simple, like "Hello world." saving the doc, and then opening that doc in Notepad. Notepad shows the .rtf formatting charters, along with the "Hello World text. Something like this, for two centered hello world sentences, in two different size Lucinda Console fonts...

Code: Text: [Select]
  1. {\rtf1\ansi\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0 Lucida Console;}}
  2. {\colortbl ;\red0\green0\blue0;}
  3. \viewkind4\uc1\pard\cf1\lang1033\f0\fs24
  4. \par
  5. \pard\qc\
  6. fs24Hello World Big!\par
  7. \par
  8. \fs1\par
  9. \fs16Hello World smaller.\par
  10. }
  11.  

So to get that at into a QB64 print routine program, you need to first make a header database...

Code: Text: [Select]
  1. {\rtf1\ansi\deff0{\fonttbl{\f0\fmodern\fprq1\fcharset0 Lucida Console;}}
  2. {\colortbl ;\red0\green0\blue0;}
  3. \viewkind4\uc1\pard\cf1\lang1033\f0\fs24
  4. \par
  5. [/html]
  6.  
  7. So let's say I save that as: [b]my_rtf_header.dat[/b]
  8.  
  9. Now let's look at the code that centers the characters on the page, \pard\qc
  10.  
  11. The code that changes font-size is \fs24 (for 24pt font size, and \fs16 (for font-size 16pt.)
  12.  
  13. To change the font size, the code is \fs1\par is used to indicate a size change is coming.
  14.  
  15. so I can assign these actions to QB64 variables like...
  16.  
  17. [code=qb64]rtf_center_text$ = "\pard\qc\par" ' Center text.
  18. rtf_font_change$ = "\fs1\par" ' Change font size.
  19. rtf_24pt$ = "\fs24" ' Font size 24.
  20. rtf_16pt$ = "\fs16" ' Font size 16.
  21. rtf_eol$ = "\par" ' End of line or paragraph
  22.  

Now to put it altogether, it would look something like this...

Code: QB64: [Select]
  1. ' CAUTION: This routine will overwrite files named as...
  2. ' $my_exp~word~pad.rtf
  3. ' $my_doc_to_print_in_wordpad.txt
  4. ' DO NOT RUN THIS ROUTINE IF ANY R YOUR FILES HAVE EITHER OF THESE NAMES IN YOUR DIRECTORY.
  5.  
  6. ' Variables needed.
  7.  
  8. rtf_center_text$ = "\pard\qc\par" ' Center text
  9. rtf_font_change$ = "\fs1\par" ' Change font size.
  10. rtf_24pt$ = "\fs24" ' Font size 24.
  11. rtf_16pt$ = "\fs16" ' Font size 16.
  12. rtf_eol$ = "\par" ' End of line or paragraph
  13.  
  14. ' First put what you want printed in a text file...
  15. OPEN "$my_doc_to_print_in_wordpad.txt" FOR OUTPUT AS #1
  16. PRINT #1, "Hello World!"
  17. PRINT #1, ""
  18. PRINT #1, "Hello World Smaller."
  19. '----------------------------------------------------
  20. ' Now add the .rtf formatting...
  21. OPEN "my_rtf_header.dat" FOR INPUT AS #1 ' Remember you need to create this file first, by saving the example in this post.
  22. OPEN "$my_doc_to_print_in_wordpad.txt" FOR INPUT AS #2 ' Can be renamed to whatever you want.
  23.  
  24. mydoc$ = "$my_exp~word~pad.rtf" ' I assigned a variable here, because this same file will be used again in the SHELL printing statement.
  25. OPEN mydoc$ FOR OUTPUT AS #3 ' Crazy name just to avoid someone overwriting an existing file. Rename this to whatever you want.
  26.  
  27. DO UNTIL EOF(1) ' Adds the .rtf header to the doc.
  28.     LINE INPUT #1, a$
  29.     PRINT #3, a$
  30.  
  31.  
  32. PRINT #3, rtf_center_text$ ' Tell Wordpad to center the text.
  33.  
  34. text_line = 0
  35. DO UNTIL EOF(2) ' This is your saved doc unformatted text file.
  36.     text_line = text_line + 1
  37.     LINE INPUT #2, text$
  38.     SELECT CASE text_line
  39.         CASE 1 ' Line 1 we want printed in 24pt.
  40.             PRINT #3, rtf_24pt$;
  41.             PRINT #3, text$ + rtf_eol$
  42.  
  43.         CASE 3 ' Line 2 we want printed in 16pt.
  44.             PRINT #3, rtf_font_change$;
  45.             PRINT #3, rtf_16pt$;
  46.             PRINT #3, text$ + rtf_eol$
  47.  
  48.         CASE ELSE
  49.             PRINT #3, text$ + rtf_eol$
  50.     END SELECT
  51. CLOSE #1, #2, #3
  52.  
  53. SHELL _DONTWAIT "notepad $my_exp~word~pad.rtf"
  54.  
  55. ' Now , print the file using wordpad minimized to the task bar.
  56.  
  57. SHELL _DONTWAIT "START /MIN WORDPAD /p " + mydoc$
  58.  

Worked as coded on my Windows 10, using QB64 v1.3. All other Qb64 versions should work as well.

Some technical stuff I don't know is the font measurements. They don't match the font selection in the Wordpad app. In other words, font-size 24, set in the code, will appear as a smaller font-size in the drop down font selection box. So it's some relative measurement like pt to em, etc. I don't really care to know why the difference, and if I was making an app with this, today, I'd either look it up or just play with some sizes until I could get a feel for it.

So fun stuff. Look some stuff p on line about .rtf code / formatting, or just play around with it like I did, and you should be able to add margins, colors, underlined text, bold text, etc. to your printing. Anyway, I hope the examples are not too confusing. Oh, and can you have a spaces between those code switches like...

 \fs16\par

written as:

\fs16 \par

YES! It allows a space, or no space. Either is fine.

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 #17 on: February 17, 2021, 12:21:35 pm »
Neat RTF file creator, Pete. I'll be saving that for future use
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #18 on: February 17, 2021, 12:29:30 pm »
Thanks Zach. If I impressed you then I'm impressed! I'm actually thinking about adding this .rtf slave printing method back into my WP project. The last time I used it was in my office software, and I just dug up another header I used for label printing...

Code: QB64: [Select]
  1. SELECT CASE LABELSIZE%
  2.     CASE 3: RTF$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\tx3960\tx7920\f0\fs20 "
  3.     CASE 2: RTF$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\tx3960\tx7920\f0\fs22 "
  4.     CASE 1: RTF$ = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}\viewkind4\uc1\pard\tx3960\tx7920\f0\fs24 "

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 #19 on: February 18, 2021, 03:23:38 am »
Thank you very much for the detailed explanation Pete.
I have already managed to print by that method.
Now I just need to find a compressed monospace font, because in some lists the lines have 150 characters and at a size smaller than 9 the letter is too small.
Another thing that I have not been able to do is write the "ñ", because I live in Spain.
Again Thank you very much for your time

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Anyone using LPRINT in QB64?
« Reply #20 on: February 18, 2021, 04:44:09 pm »
In .rtf code, ñ would be...

Code: QB64: [Select]
  1. \'f1

Not sure what to say about the compressed font.

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 #21 on: February 19, 2021, 04:07:20 am »
Thanks again Pete.

As I have seen, the character must be replaced by this complete line so that the "ñ" appears

"{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2699718 \'f1"

And in the case of the "Ñ" it would be this line

"{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid2699718 \'d1"