Printing reports
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Printing reports
I am writing a program which generates some reports that must have the possibility to be printed on a (air)printer.
Currently i found a method, but it is a very clumsy one. Perhaps some of you have better ideas, but first i will point out my clumsy method.
1. In the (SB) program, the output font is set to a fixed pitch font, i used 'Courier'.
2. Each line is first built up in a string, using formatting functions for text and numbers.
3. The line is the printed on screen, and, depending on a switch, also to an ascii printfile. So far, so good (see picture 1.)
4. The printfile is then ported from the SB sandbox to an app that can print to a printer, using copy/paste. I tried "Notes" and "Pages". In both cases the font information is lost and the report becomes a mess (see picture 2)
5. Only in "Pages", the "Courier' font can be defined again and the report looks good again and may be printed using airprint. (See picture 3.)
My question is whether there is a more simple, direct method.
A SB file command, sending a file to a printer would be the best option, but may not be expected any soon.
Is it possible to write a function using the browser facilities in SB?
After all, an (air)printer has its own local(?) IP adress, and a browser must be able to send text to an URL?
I have very little experience using browser and other internet stuff, hence i put the question here.
If it can be done, i will write some functions to print multi-page reports in a proper way. I used them in the good old DOS period, using Borland's turbo-C.
Picture one, report on screen (and when viewing the printfile).
Picture two, printfile arriving at "Notes" or "Pages"
Picture three, printed by "Pages" after selecting "Courier" font again.
Currently i found a method, but it is a very clumsy one. Perhaps some of you have better ideas, but first i will point out my clumsy method.
1. In the (SB) program, the output font is set to a fixed pitch font, i used 'Courier'.
2. Each line is first built up in a string, using formatting functions for text and numbers.
3. The line is the printed on screen, and, depending on a switch, also to an ascii printfile. So far, so good (see picture 1.)
4. The printfile is then ported from the SB sandbox to an app that can print to a printer, using copy/paste. I tried "Notes" and "Pages". In both cases the font information is lost and the report becomes a mess (see picture 2)
5. Only in "Pages", the "Courier' font can be defined again and the report looks good again and may be printed using airprint. (See picture 3.)
My question is whether there is a more simple, direct method.
A SB file command, sending a file to a printer would be the best option, but may not be expected any soon.
Is it possible to write a function using the browser facilities in SB?
After all, an (air)printer has its own local(?) IP adress, and a browser must be able to send text to an URL?
I have very little experience using browser and other internet stuff, hence i put the question here.
If it can be done, i will write some functions to print multi-page reports in a proper way. I used them in the good old DOS period, using Borland's turbo-C.
Picture one, report on screen (and when viewing the printfile).
Picture two, printfile arriving at "Notes" or "Pages"
Picture three, printed by "Pages" after selecting "Courier" font again.
- Dutchman
- Posts: 851
- Joined: Mon May 06, 2013 9:21 am
- My devices: iMac, iPad Air, iPhone
- Location: Netherlands
- Flag:
Re: Printing reports
- Toolbar off
- Make screenshot
- Print picture from album
Is that a solution?
- Make screenshot
- Print picture from album
Is that a solution?
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Printing reports
Thanks Ton, i didn't come up with that one.
It is another solution for single page reports. It is printed directly from the SB sandbox, hence no other apps needed, but yet "manual" actions required.
It really would make SB a "professional" tools if a proper (air)printfacility were present.
More ideas? What about the browser possibilities?
It is another solution for single page reports. It is printed directly from the SB sandbox, hence no other apps needed, but yet "manual" actions required.
It really would make SB a "professional" tools if a proper (air)printfacility were present.
More ideas? What about the browser possibilities?
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Printing reports
https://www.w3schools.com/jsref/met_win_print.asp
"Try it yourself" button generates a simple example code.
"Try it yourself" button generates a simple example code.
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Printing reports
Has anyone gotten this example to work in SB?
I wrote the following small program to test it. My screen showed the button, but it didn't do anything.
I wrote the following small program to test it. My screen showed the button, but it didn't do anything.
Code: Select all
N$="browse"
q$=chr$(34)
a$=""
t$="<!DOCTYPE html><html><body><p>Click the button to print the current page.</p><button onclick="&q$&"myFunction()"&q$&">Print this page</button><script>function myFunction() {window.print();}</script></body></html>"
BROWSER N$ URL A$ AT 30,30 SIZE 500,300
BROWSER N$ TEXT t$
pause 10
- Attachments
-
- 66F7491E-A931-40FA-9F8D-FAF52AD08BF5.jpeg (43.77 KiB) Viewed 3191 times
The only thing that gets me down is gravity...
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Printing reports
Tried another way. I created a separate file that contains the exact W3 example code:
Next, the program to display it:
Same result.
Maybe Dutchman or Dav could find a solution. They have done some amazing work with JavaScript.
Code: Select all
<!DOCTYPE html>
<html>
<body>
<p>Click the button to print the current page.</p>
<button onclick="myFunction()">Print this page</button>
<script>
function myFunction() {
window.print();
}
</script>
</body>
</html>
Code: Select all
N$="browse"
q$=chr$(34)
a$="print.html"
BROWSER N$ URL A$ AT 30,30 SIZE 500,300
pause 10
Maybe Dutchman or Dav could find a solution. They have done some amazing work with JavaScript.
The only thing that gets me down is gravity...
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Printing reports
I tried one more time, using the SB browser to load the W3School's demo page for Window.print. Still nothing when I press the print button, so I am convinced that it is an SB browser issue.
Henk, I have another way to print from Smart Basic. Here is a program that will load a text file of data and generate a pre-addressed Mail email message to you containing the data. Once you send it, you can print the received message, with all your columns intact. No copying or pasting needed - just push a few buttons. Maybe it will work for you until we get a better solution.
Instructions are in the comments at the top of the program.
Henk, I have another way to print from Smart Basic. Here is a program that will load a text file of data and generate a pre-addressed Mail email message to you containing the data. Once you send it, you can print the received message, with all your columns intact. No copying or pasting needed - just push a few buttons. Maybe it will work for you until we get a better solution.
Instructions are in the comments at the top of the program.
Code: Select all
/*
Send Text to Mail
by rbytes, April 2018
1. Prepare your data file
2. Enter the data filename and your email address in the green area.
3. Run the program. Your data should appear in the browser window.
4. Press the Mail button and Confirm link to send your data to a Mail message,
already addressed to you.
5. Press Send to send the message.
6. When you receive the message you can print it.
I used Menlo, a fixed-width font, so your columns will stay aligned.
*/
'g'
' Enter the name of your text file to load
fname$="numbers.txt"
' Enter your email address
email$="nobody@all.com"
''
if file_exists(fname$) then
file fname$ setpos 0
while not file_end(fname$)
file fname$ readline temp$
content$&=temp$&"<br>"
end while
end if
SET BUTTONS CUSTOM
path$=""
GET SCREEN SIZE sw,sh
/* for iPhone testing
sw=568
sh=320*/
rw=sw/1024!rh=sh/768
'init screen
GRAPHICS
GRAPHICS CLEAR .7,.7,.7
DRAW FONT SIZE 20*rw
DRAW FONT NAME "Arial"
FILL COLOR .9,.9,.9
GOSUB makebuttons
gosub definestrings
BROWSER "preview" AT 10*rw,10*rh SIZE sw-20,sh-60
body$= "<font face='Menlo'>"&content$&"</font>"
' assemble a$ from a1$(html),a2$(title),a3$(html),a4$(body) and a2$(html)
title$="Print This"
GOSUB definestrings
a$=a1$&a1a$&a1b$&a1c$&a2$&a3$&a4$&a5$
b$=a1$&a4$&a5a$
BROWSER "preview" text b$
do
IF bp("mail") THEN
BROWSER "n" AT 600*rw,720*rh SIZE 80*rw,30*rh
BROWSER "n" TEXT a$
BROWSER "n" SHOW
ENDIF
slowdown
until 0
'----------
makebuttons:
'----------
FILL ALPHA 0
SET BUTTONS FONT SIZE 20*rw
BUTTON "mail" TEXT "MAIL" AT 400*rw,720*rh SIZE 100*rw,40*rh
FILL ALPHA 1
RETURN
'----------
definestrings:
'----------
a1$="<html><head><title>PRINT NOTE</title></head><body><font face='Courier'>"
a1a$="<a href="&CHR$(34)&"mailto:"
a1b$=email$
a1c$="?subject="
a2$=title$&lin$&lin$ ' title field
a3$="&body="
a4$=body$ ' body field
a5$="</font>"&CHR$(34)&">Confirm</a></body></html>"
a5a$="</font></body></html>"
RETURN
DEF bp(a$) = BUTTON_PRESSED(a$)
The only thing that gets me down is gravity...
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Printing reports
Ok, and what if to try this printing webpage not from sB browser but from Safari?
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Printing reports
Hi Richard,rbytes wrote: ↑Tue Jul 03, 2018 5:00 amI tried one more time, using the SB browser to load the W3School's demo page for Window.print. Still nothing when I press the print button, so I am convinced that it is an SB browser issue.
Henk, I have another way to print from Smart Basic. Here is a program that will load a text file of data and generate a pre-addressed Mail email message to you containing the data. Once you send it, you can print the received message, with all your columns intact. No copying or pasting needed - just push a few buttons. Maybe it will work for you until we get a better solution.
Instructions are in the comments at the top of the program.
I followed yor instruction carefully, but ended up with an empty mail body (just telling : PRINT THIS
Anyhow, i am looking for a method that can be executed from within a SB program, wich does not require intermediate actions. Let me clarify. I have the following reports menu:
And for each of the reports, the (relevant) structure is as follows:
Code: Select all
'
Structure of printing program
'
for i=1 to n_lines
t$=..... ' prepare the i'th line
print t$ ' put the line on the screen
if switch("prt") then ' add the line to printfile
file fname$ print t$
endif
next i
' so far the existing code. What I would like to add :
if switch("prt") then
file fname$ to printer ' this would be a nice SB command
or
send-to-printer(fname$) ' self written function in SB
end if
............
So, before i start the program, i run to the 1st floor, start my printer, and go back downstairs.
I start the program, do things, then select the report menu, switch the switch on if i want the stuff on paper and select a report. The report appears on the screen, and i would like to hear my printer start printing the chosen report. That's how things should work.
If it is not possible and "manual" actions are needed, then i am quite happy with the copy/paste to "Pages" method.
- rbytes
- Posts: 1338
- Joined: Sun May 31, 2015 12:11 am
- My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet - Location: Calgary, Canada
- Flag:
- Contact:
Re: Printing reports
Odd that you ended up with a blank email, Henk, but no use troubleshooting the program right away, since it doesn't meet your needs. I will check it out in a few days, in case anyone else wants to use it.
Mr. K, in answer to your question, yes, the JavaScript Window.print command does work in Safari, but not in the Smart Basic browser.
Mr. K, in answer to your question, yes, the JavaScript Window.print command does work in Safari, but not in the Smart Basic browser.
The only thing that gets me down is gravity...