Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
06-03-2024, 11:08 PM
(This post was last modified: 06-03-2024, 11:09 PM by SMcNeill.)
A little routine I wrote which should print out a file to the printer:
Code: (Select All)
$COLOR:32
PrintScreen = _NEWIMAGE(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
SCREEN PrintScreen
File$ = _OPENFILEDIALOG$("Choose file to Print", _CWD$, "*.*", "Any File")
OPEN File$ FOR BINARY AS #1
CLS , White, PrintScreen
COLOR Black, 0
DO
LINE INPUT #1, temp$
PCOPY 0, 1
PRINT temp$
IF CSRLIN >= _HEIGHT - 3 THEN 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
PCOPY 1, 0
_PRINTIMAGE PrintScreen
CLS , White, PrintScreen
PRINT temp$
END IF
LOOP UNTIL EOF(1)
CLOSE
Problem is, when I went to test it, my printer is all out of ink and such.
Anyone want to give this a test run for us? Uses _PrintImage, so is a Windows-Only program, so Linux and Mac folks can't make yse of this until we expand the functionality to include them.
If you can, try this with a short, 1-page program (Hello World would work fine.) Then try it with something that might take a couple of pages to print out. It *should* sort things out and print across multiple pages without issue.
I hope, anyway.
Note: IF this prints out 1000 pages and doesn't stop.... I apologize in advance!
Posts: 3,987
Threads: 178
Joined: Apr 2022
Reputation:
222
06-04-2024, 12:11 AM
(This post was last modified: 06-04-2024, 01:47 AM by bplus.)
first couple of tries were solid blocks of black, so i modified your code to get desired results 65 66 lines per page
Code: (Select All) PrintScreen = _NewImage(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
Screen PrintScreen
Color &HFF000000, &HFFFFFFFF
File$ = _OpenFileDialog$("Choose file to Print", _CWD$, "*.*", "Any File")
If File$ <> "" Then
Open File$ For Binary As #1
Cls
Do
Line Input #1, temp$
Print temp$
pline = pline + 1
If pline > 65 Then 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
_PrintImage PrintScreen
Cls
pline = 0
End If
Loop Until EOF(1)
_PrintImage PrintScreen
Close
End If
looks like it is fitting about 100+ chars across page and continues onto next line if it runs over, so lines wont fit page if lines continuously go beyond 100 chars.
look forward to fonts and color keywords oh wait, i don't have ink i use B&W toner ;(
b = b + ...
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
06-04-2024, 02:23 AM
(This post was last modified: 06-04-2024, 10:20 AM by SMcNeill.)
@bplus give this a shot:
Code: (Select All)
$COLOR:32
$RESIZE:SMOOTH
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NEWIMAGE(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
SCREEN PrintScreen
File$ = _OPENFILEDIALOG$("Choose file to Print", _CWD$, "*.*", "Any File")
OPEN File$ FOR BINARY AS #1
IF _FILEEXISTS(File$) = 0 THEN SYSTEM
CLS , White, PrintScreen
COLOR Black, 0
height = INT(_HEIGHT / _FONTHEIGHT - 3)
DO
LINE INPUT #1, temp$
PCOPY 0, 1
PRINT temp$
IF CSRLIN >= height THEN 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
PCOPY 1, 0
_PRINTIMAGE PrintScreen
SLEEP 'A break so we can see which page we just printed
CLS , White, PrintScreen
PRINT temp$
END IF
LOOP UNTIL EOF(1)
CLOSE
_PRINTIMAGE PrintScreen
I'm thinking the only real change you needed to make was to fix the _HEIGHT issue. I'd failed to / _FontHeight, which means the page scrolled itself to death before printing and going to the next page.
-- EDIT: To make certain the last page prints for us.
Posts: 200
Threads: 5
Joined: Apr 2022
Reputation:
22
06-04-2024, 03:13 AM
(This post was last modified: 06-04-2024, 04:54 AM by JRace.)
GAH! You went and changed the program as I was pulling together my results!
Curse these slow fingers!
OK, here's my infodump:
The new version works better than the previous, which had obvious issues, buuuuut....
(I tested the new version on all 3 of the files listed below.)
(This was when "printing" to PDF files. Sorry, no live print test. I do not currently have a printer hooked up.)
It's not printing non-full pages. And it seems to be leaving one black line at the bottom of unprinted pages:
Three file print results: - Program source: 2/5 of a page. Appeared on screen, but nothing "printed" to PDF.
- Creative Computing's DOCTOR program: only printed the first page (63 lines). The second page would have been 20 lines.
- A list of PE keywords: got 13 full pages. Does not seem to have lost or skipped any lines on the "printed pages". The 14th page would have been only 4 lines, if it had been "printed".
For the morbidly curious, here's my original, incomplete, now defunct, report:
(Again, everything below refers to the originally posted test program)
Looks like it displays 50 lines of 105 characters.
Nothing got sent to the print queue in any of these tests.
Your test program displays cleanly. I added a 150 character wide "ruler line" to the top for informational purposes.
[testprog]
On a list of PE keywords it seems to have lost the first 5 lines, then printed more lines than I could capture. (I only caught 39 lines, but a sliver of line 40 is there)
And I HAD to capture the image with a screen recorder because the image flashed onto the screen then disappeared, leaving a black, empty window.
[keywords]
On Creative Computing's DOCTOR.BAS it lost the first 17 lines, then printed 50, leaving a black rectangle at the bottom of the window.
[ccdoctor]
Posts: 3,987
Threads: 178
Joined: Apr 2022
Reputation:
222
06-04-2024, 09:02 AM
(This post was last modified: 06-04-2024, 09:17 AM by bplus.)
(06-04-2024, 02:23 AM)SMcNeill Wrote: @bplus give this a shot:
Code: (Select All)
$COLOR:32
$RESIZE:SMOOTH
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NEWIMAGE(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
SCREEN PrintScreen
File$ = _OPENFILEDIALOG$("Choose file to Print", _CWD$, "*.*", "Any File")
OPEN File$ FOR BINARY AS #1
IF _FILEEXISTS(File$) = 0 THEN SYSTEM
CLS , White, PrintScreen
COLOR Black, 0
height = INT(_HEIGHT / _FONTHEIGHT - 3)
DO
LINE INPUT #1, temp$
PCOPY 0, 1
PRINT temp$
IF CSRLIN >= height THEN 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
PCOPY 1, 0
_PRINTIMAGE PrintScreen
SLEEP 'A break so we can see which page we just printed
CLS , White, PrintScreen
PRINT temp$
END IF
LOOP UNTIL EOF(1)
CLOSE
I'm thinking the only real change you needed to make was to fix the _HEIGHT issue. I'd failed to / _FontHeight, which means the page scrolled itself to death before printing and going to the next page.
i had to add something on end to get the last and partial page printed, then i made this sucker more interesting ;-))
Code: (Select All) $Color:32
$Resize:Smooth
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NewImage(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
Screen PrintScreen
f& = _LoadFont("arial.ttf", 18)
_Font f&
File$ = _OpenFileDialog$("Choose file to Print", _CWD$, "*.*", "Any File")
Open File$ For Binary As #1
If _FileExists(File$) = 0 Then System
Cls , White, PrintScreen
Color Black, 0
height = Int(_Height / _FontHeight(f&) - 3)
page = 1
fname$ = Mid$(File$, _InStrRev(File$, "/") + 1)
Do
Line Input #1, temp$
PCopy 0, 1
Print temp$
If CsrLin >= height Then 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
PCopy 1, 0
'_PrintImage PrintScreen
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
page = page + 1
Sleep 'A break so we can see which page we just printed
Cls , White, PrintScreen
Print temp$
End If
Loop Until EOF(1)
PCopy 1, 0
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
Close
Cls , White, PrintScreen
Print "Files ready"
sample file:
b = b + ...
Posts: 3,987
Threads: 178
Joined: Apr 2022
Reputation:
222
06-04-2024, 09:20 AM
(This post was last modified: 06-04-2024, 09:21 AM by bplus.)
dang can't get this to finish right
b = b + ...
Posts: 3,987
Threads: 178
Joined: Apr 2022
Reputation:
222
i think this is better
Code: (Select All) $Color:32
$Resize:Smooth
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NewImage(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
Screen PrintScreen
f& = _LoadFont("arial.ttf", 18)
_Font f&
File$ = _OpenFileDialog$("Choose file to Print", _CWD$, "*.*", "Any File")
Open File$ For Binary As #1
If _FileExists(File$) = 0 Then System
Cls , White, PrintScreen
Color Black, 0
height = Int(_Height / _FontHeight(f&) - 3)
page = 1
fname$ = Mid$(File$, 1, _InStrRev(File$, ".") - 1)
Print: Print
Do
Line Input #1, temp$
'PCopy 0, 1
nline = nline + 1
Print nline; temp$
If CsrLin >= height Then 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
'PCopy 1, 0
'_PrintImage PrintScreen
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
page = page + 1
Sleep 'A break so we can see which page we just printed
Cls , White, PrintScreen
'Print temp$ ' why print again
Print: Print
End If
Loop Until EOF(1)
'PCopy 1, 0
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
Sleep
Close
Cls , White, PrintScreen
Print "Files ready"
b = b + ...
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
(06-04-2024, 10:01 AM)bplus Wrote: i think this is better
Code: (Select All) $Color:32
$Resize:Smooth
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NewImage(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
Screen PrintScreen
f& = _LoadFont("arial.ttf", 18)
_Font f&
File$ = _OpenFileDialog$("Choose file to Print", _CWD$, "*.*", "Any File")
Open File$ For Binary As #1
If _FileExists(File$) = 0 Then System
Cls , White, PrintScreen
Color Black, 0
height = Int(_Height / _FontHeight(f&) - 3)
page = 1
fname$ = Mid$(File$, 1, _InStrRev(File$, ".") - 1)
Print: Print
Do
Line Input #1, temp$
'PCopy 0, 1
nline = nline + 1
Print nline; temp$
If CsrLin >= height Then 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
'PCopy 1, 0
'_PrintImage PrintScreen
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
page = page + 1
Sleep 'A break so we can see which page we just printed
Cls , White, PrintScreen
'Print temp$ ' why print again
Print: Print
End If
Loop Until EOF(1)
'PCopy 1, 0
_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
Sleep
Close
Cls , White, PrintScreen
Print "Files ready"
The problem with what you see there, @bplus , is if that last line contains more characters than can print on a single line.
Let's say your font allows for 100 characters to be printed on a single line. If that last line is 105 characters, it's going to fall down to the next line on the page -- which qill trigger QB64's automatic page scrolling....
You've just cut off the first line on that page as it scrolled out of existence before you could print it to your printer!
-- And that's why it does the PCOPY to the point BEFORE that last line was printed, and then moves it to the top of the next page.
Posts: 3,987
Threads: 178
Joined: Apr 2022
Reputation:
222
06-04-2024, 10:28 AM
(This post was last modified: 06-04-2024, 10:29 AM by bplus.)
OK you are responding to this;
Code: (Select All) 'Print temp$ ' why print again
For me testing with bas files, it works fine without the pcopy lines.
i just confirmed this prints exactly same as saved images (save paper and ink with saveimage);
Code: (Select All) $Color:32
$Resize:Smooth
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NewImage(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
Screen PrintScreen
f& = _LoadFont("arial.ttf", 18)
_Font f&
File$ = _OpenFileDialog$("Choose file to Print", _CWD$, "*.*", "Any File")
Open File$ For Binary As #1
If _FileExists(File$) = 0 Then System
Cls , White, PrintScreen
Color Black, 0
height = Int(_Height / _FontHeight(f&) - 3)
page = 1
fname$ = Mid$(File$, 1, _InStrRev(File$, ".") - 1)
Print: Print
Do
Line Input #1, temp$
nline = nline + 1
Print nline; temp$
If CsrLin >= height Then 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
_PrintImage PrintScreen
'_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
page = page + 1
Sleep 'A break so we can see which page we just printed
Cls , White, PrintScreen
Print: Print
End If
Loop Until EOF(1)
_PrintImage PrintScreen
'_SaveImage fname$ + Str$(page) + ".PNG", PrintScreen
Sleep
Close
Cls , White, PrintScreen
Print "Files ready"
b = b + ...
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
You're not seeing what I'm saying. Try this:
Code: (Select All)
$COLOR:32
$RESIZE:SMOOTH
'Resize is so we can drag/resize the screen so it fits on a monitor
PrintScreen = _NEWIMAGE(850, 1100, 32) 'to represent an 8.5" x 11" sheet of paper
SCREEN PrintScreen
f& = _LOADFONT("arial.ttf", 18)
_FONT f&
'File$ = _OPENFILEDIALOG$("Choose file to Print", _CWD$, "*.*", "Any File")
file$ = "temp.txt"
OPEN file$ FOR BINARY AS #1
IF _FILEEXISTS(file$) = 0 THEN SYSTEM
DIM A_long_line AS STRING
FOR i = 1 TO 500
A_long_line = A_long_line + CHR$(INT(RND * 26 + 65))
NEXT
A_long_line = A_long_line + CHR$(13) + CHR$(10)
FOR i = 1 TO 50
PUT #1, , A_long_line
NEXT
SEEK #1, 1
CLS , White, PrintScreen
COLOR Black, 0
height = INT(_HEIGHT / _FONTHEIGHT(f&) - 3)
page = 1
fname$ = MID$(file$, 1, _INSTRREV(file$, ".") - 1)
PRINT: PRINT
DO
LINE INPUT #1, temp$
nline = nline + 1
PRINT nline; temp$
IF CSRLIN >= height THEN 'we probably scrolled the page. Rip off this sheet of paper and start a new page!
'_PRINTIMAGE PrintScreen
_SAVEIMAGE fname$ + STR$(page) + ".PNG", PrintScreen
page = page + 1
'SLEEP 'A break so we can see which page we just printed
CLS , White, PrintScreen
PRINT: PRINT
END IF
LOOP UNTIL EOF(1)
'_PRINTIMAGE PrintScreen
_SAVEIMAGE fname$ + STR$(page) + ".PNG", PrintScreen
SLEEP
CLOSE
CLS , White, PrintScreen
PRINT "Files ready"
Notice how the top of that first line is cut off? The last line on the page was too long for the page and, as such, it caused the screen to scroll up.
THAT's what the PCOPY undoes and then moves that line to the next page for us.
|