Posts: 383
Threads: 56
Joined: Apr 2022
Reputation:
13
Hi, I have just recently found my program needs to print out some of the results on paper. I much prefer to print to the screen however now find I can compare present results better if I had a printed copy of the past results. I was sure I'd be able to search our site for hints on this topic but wasn't able to find a clue as to what I'm missing in the code I have picked up from the WIKI.
If you can see where I may be going wrong, thanks in advance for your help. This code I'm using is printing a BLACK page on my printer and I can't tell if it is printing the test phrase or not.
Code: (Select All) 'NOTE: THIS ROUTINE DOESN'T WORK ... SUPPOSTED HAVE A WHITE BACKGROUND BUT GETTING AN ALL BLACK INK PAGE
'Printing on the Printer - an example using "_PrintImage" command
'Assumes a menu where an option to print to printer is the letter "p" or "P"
DIM img AS LONG
DIM Page AS LONG
PageScale = 10
PageHeight = 297 * PageScale
PageWidth = 210 * PageScale
Page& = _NEWIMAGE(PageWidth, PageHeight, 32)
a$ = "P"
Text$ = "The Rain in Spain falls mainly in the Plain."
PRINT
PRINT
PRINT Text$ 'This text is printing to the screen ok
IF a$ = "p" OR a$ = "P" THEN
IF img& <> 0 THEN _FREEIMAGE (img&)
_DEST Page& ' This is meant to capture the PRINTER data, making the size of the print the same size as the typical paper found in the printer and set the focus to the printer
CLS , _RGB32(255, 255, 255) ' Insterestingly, this CLS does not Clear the computer screen but setting the RGB color to white seems to NEED Cls plus the comma, _RGB(255,255,255) on it's own generates an error
' according to the _PRINTIMAGE wiki , this line sets a white background
'.....I think things go wrong from here on down. .....
_DEST 0 ' This is supposed to set the focus on the computer screen
_PRINTSTRING (1, 1), Text$ 'This re-writes the phrase to the computer screen, so the phrase is written once at line 22 and again here
img& = _COPYIMAGE(0) ' This is supposed to capture the computer screen where the phrase is written twice
_PRINTIMAGE img& ' this command is supposed to send the img just captured to the printer
_DELAY 5
END IF
Posts: 2,177
Threads: 222
Joined: Apr 2022
Reputation:
104
I haven't worked with _PRINTIMAGE before, but from reading your code it appears to me the image you are capturing with img& has a black background. I would think you would want to write your text to the Page& screen, instead, and capture that image to send to the printer.
Pete
Shoot first and shoot people who ask questions, later.
Posts: 415
Threads: 75
Joined: Apr 2022
Reputation:
22
People don't use PRINTIMAGE with text, they use it with graphics. Most likely the black background of your screen is flooding the tiny white fonts of your text. Instead of PRINTIMAGE and COPYIMAGE and FREEIMAGE you should just use: LPRINT Text$ and it will print it directly to your printer.
Posts: 415
Threads: 75
Joined: Apr 2022
Reputation:
22
Posts: 3,978
Threads: 177
Joined: Apr 2022
Reputation:
220
07-12-2022, 05:53 PM
(This post was last modified: 07-12-2022, 05:55 PM by bplus.)
This worked fine for me, I even had to reload my printer driver and stuff first because working from fresh SSD drive.
Code: (Select All) 'NOTE: THIS ROUTINE DOESN'T WORK ... SUPPOSTED HAVE A WHITE BACKGROUND BUT GETTING AN ALL BLACK INK PAGE
'Printing on the Printer - an example using "_PrintImage" command
'Assumes a menu where an option to print to printer is the letter "p" or "P"
Dim img As Long
Dim Page As Long
Screen _NewImage(800, 600, 32)
PageScale = 2
PageHeight = 297 * PageScale
PageWidth = 210 * PageScale
Page& = _NewImage(PageWidth, PageHeight, 32) ' Page& ready to take an image
a$ = "P"
Text$ = "The Rain in Spain falls mainly in the Plain."
Color _RGB32(0, 0, 0), _RGB32(255, 255, 255)
Cls
Print
Print
Print Text$ 'This text is printing to the screen ok <<<< really? was it black on white back ground?
If a$ = "p" Or a$ = "P" Then ' print it
' screen image to page
_PutImage , 0, Page&
' now check out page&
Screen _NewImage(PageWidth, PageHeight, 32)
_PutImage , Page&, 0
_PrintString (10, 297 - 8), "Does this preview look OK? y/n"
k$ = InKey$
While k$ <> "y" And k$ <> "n"
k$ = InKey$
Wend
If k$ = "y" Then
PageScale = 10
PageHeight = 297 * PageScale
PageWidth = 210 * PageScale
Page2& = _NewImage(PageWidth, PageHeight, 32) ' Page& ready to take an image
_PutImage , Page&, Page2&
_PrintImage Page2& ' this command is supposed to send the img just captured to the printer
End If
End If
I used a graphics screen for easy (for me) manipulation of images.
The printout was the one line down (one page only) about 1/16 th of page from top black print on white background. The font was as crappy looking as in preview (see snapshot) because your page is not scaled with screen, ie different ratios width x height...
b = b + ...
Posts: 383
Threads: 56
Joined: Apr 2022
Reputation:
13
Thanks guys - I literally thought I was following the directions in the wiki. As Pete said the black must have been coming from my computer screen even though I thought I was setting the foreground and background colors correctly. Sierra I have used LPrint, and only LPrint if I want to send something to my printer but was hoping to find a better path (quicker) path to the printer.
I'm not sure where that font came from bplus. The only printed version of that rain/spain phrase was on my computer screen and it did not look like that. Your code does work for me but I agree the font looks awful. I expected the screen font to be the same font directed to the printer. The only thing I thought I needed to worry about was the difference in rows/columns I had on the screen v's that available to me in an 8x10 piece of paper in the printer.
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
This is according to the QBasic Reference Guide; Screenshot. It doesn't work. Maybe it is because:
"The LPRINT USING statement sends formatted data to LPT1, the parallel port printer."
My printer is connected to USB. It is an HP Deskjet Plus 4120.
Posts: 3,978
Threads: 177
Joined: Apr 2022
Reputation:
220
07-12-2022, 11:16 PM
(This post was last modified: 07-12-2022, 11:21 PM by bplus.)
Quote:I'm not sure where that font came from bplus. The only printed version of that rain/spain phrase was on my computer screen and it did not look like that. Your code does work for me but I agree the font looks awful. I expected the screen font to be the same font directed to the printer. The only thing I thought I needed to worry about was the difference in rows/columns I had on the screen v's that available to me in an 8x10 piece of paper in the printer.
Sorry I misspoke, it's not the font that is the problem, it is the stretching and shrinking of it to fit in the image containers. If you keep the ratios of screen to printer paper the same the font will not be badly distorted. When I was printing calendars from screen I used _PutImage to rotate from portrait to landscape view for _PrintImage, Rotozoom could do it too.
For an 8.5 x 11 inch paper = (4.25 x 5.5) * 100 is 425 x 550. Try that screen size in code I modified. Should magnify the print with little distortion.
Or the 210 x 297 ratio .7070 hmm... 8.5/11 = .7727...If your paper is 210 x 297 something units, try screen size 420 X 594.
b = b + ...
Posts: 415
Threads: 75
Joined: Apr 2022
Reputation:
22
07-13-2022, 01:09 AM
(This post was last modified: 07-13-2022, 01:12 AM by SierraKen.)
(07-12-2022, 09:02 PM)Kernelpanic Wrote: This is according to the QBasic Reference Guide; Screenshot. It doesn't work. Maybe it is because:
"The LPRINT USING statement sends formatted data to LPT1, the parallel port printer."
My printer is connected to USB. It is an HP Deskjet Plus 4120.
In QB64 LPRINT detects USB printers. It says on the Wiki help page. I'm not sure about LPRINT USING https://qb64phoenix.com/qb64wiki/index.php/LPRINT
Posts: 11
Threads: 3
Joined: Apr 2022
Reputation:
1
07-13-2022, 01:25 AM
(This post was last modified: 07-13-2022, 01:27 AM by George McGinn.
Edit Reason: Spacing was messed up
)
I too had this issue for an application I wrote that needed to print baseball team statistics on paper so a manager could give them out to his players.
The following works on both Linux and MAC (I don't have a Windows machine, so I can't speak to that).
I first create an output file with what I print, then I SHELL out to enscript. The code looks something like:
Code: (Select All) cmd = "enscript -B -r -fCourier8 " + ReportFile$
SHELL (cmd)
ReportFile$ is the formatted file I want to print. It prints to my HP Laser printer, or whatever printer I have set as my default printer.
You have to make sure that enscript is installed on your Linux or Mac.
One note for Mac users, and I don't know if this is due to my printer or the way that Mac's version of enscript works, but I had to add 8 spaces to the left side of every line printed, otherwise it doesn't print correctly.
If I recall, I had to use Brew to install enscript on my Mac, as it was removed from the App Store awhile back.
With enscript, you can print in both portrait and landscape mode. I believe the -r parameter tells it to print in landscape.
—————————————————————————————
George McGinn
Theoretical/Applied Computer Science Specialist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
Society of American Baseball Research
|