Printing reports

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Printing reports

Post by Henko »

Hi George,

I am a bit puzzled by your post in this thread; i'll explain why.

In this thread a very simple method is explained how to print directly from a running sB program on a printer. In short: no more is needed than 12 lines of Python code on a Windows PC, Python beiing a free product, wich may be installed in a matter of minutes. The thread contains the Python applet, and a detailed description of the method and the needed steps.
Did you read the thread or only the title of the thread?

In your post it is stated that the ONLY way of direct printing is making use of "App extentions". That may be one method, but it needs to be implemented in the sB interpreter, and that is not the case. So, what is the value of this statement?

At the end of your post you mention the possibility to transfer a printfile to an text processing app and perform the printing from that app. That's exactly the method that i mentioned in the very beginning of the thread, calling it a very clumsy method, beiing the reason for further research.

A sB user, opening this thread and starting to read the most recent (your) post, will immidiately conclude that direct printing from a sB program is not possible, which is untrue.

So, i'm rather puzzled what is going on here.

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Printing reports

Post by GeorgeMcGinn »

Sorry for a late response, as I had to moved, was hospitalized twice, and recently visited the ER due to a 75lb box crushing my last two toes on my left foot, and created two-dozen hairline fractures on my foot and toes.

Eventually you need to create your App in XCode, and your solution isn't practical for those who are really not programmers. You can ask Rbytes, but I even created on my dedicated server a website called appfileserver.net, which had the same ideas you brought up. Not only printing, but providing access to very large files by using the HTTP statements to pass a key to a script and it returns the record requested.

The issue is getting that past Apple, as it looked to them a lot like the Dropbox issue. I think because SB is very powerful, it is feared. We can work around most of the framework and create an open system rather than their closed system architecture. My app can create a file, and your app, could access that data created outside Apple's container system, and by bypassing their existing framework and container system Apple would never allow this to occur.

That is why all the serious games are written in Objective C or SWIFT as App Extensions to access printers and web-based files are all contained by Apple and it's closed framework.

I never meant to say or imply what you propose can't be done. Rbytes and I did limited testing. But to create an app to iTunes using that will never pass its inspection, and you and I would be treated like Mr K is with Dropbox.

You and I know we can code any work-around to a problem, but will we get it past Apple if we want to include it in an App?



Henko wrote:
Wed Jul 18, 2018 8:58 am
Hi George,

I am a bit puzzled by your post in this thread; i'll explain why.

In this thread a very simple method is explained how to print directly from a running sB program on a printer. In short: no more is needed than 12 lines of Python code on a Windows PC, Python beiing a free product, wich may be installed in a matter of minutes. The thread contains the Python applet, and a detailed description of the method and the needed steps.
Did you read the thread or only the title of the thread?

In your post it is stated that the ONLY way of direct printing is making use of "App extentions". That may be one method, but it needs to be implemented in the sB interpreter, and that is not the case. So, what is the value of this statement?

At the end of your post you mention the possibility to transfer a printfile to an text processing app and perform the printing from that app. That's exactly the method that i mentioned in the very beginning of the thread, calling it a very clumsy method, beiing the reason for further research.

A sB user, opening this thread and starting to read the most recent (your) post, will immidiately conclude that direct printing from a sB program is not possible, which is untrue.

So, i'm rather puzzled what is going on here.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Printing reports

Post by Henko »

Sorry to hear about your misfortune with your foot.
Thanks for your answer to my question "what's going on?"
There is a big misunderstanding between us: I have no intention whatsoever to publish an app on the Appstore. I sought and found a method to be able to print at my home, directly from a SB program, using one of my PC's and the laserprinter. And i communicated that (simple) solution in full to other interested SB programmers.
That's all.

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Printing reports

Post by GeorgeMcGinn »

You are right. I have confused one for the other here. My apologies for confusing the issue more.

I've been looking for an easy way to print from an App. I had a workaround to print from the programs running on the IDE, but with close to 2 gigs of program source code in my SB app, I can't seem to find it (one of the things I will be adding to my IDE/Dropbox replacement is not only a better search tool, but a program to identify duplicates plus. Two or more either with the same name and/or lengths with similar hash totals. I know for some programs I have 5+ copies, and I need time to sort them out.

So yes, I too am interested in that and will look at your solution. Sometimes with large source code, it helps to print it out once so I can do a thorough walk-through of the source and be able to write on it.

Thanks.


Henko wrote:
Wed Sep 05, 2018 11:39 am
Sorry to hear about your misfortune with your foot.
Thanks for your answer to my question "what's going on?"
There is a big misunderstanding between us: I have no intention whatsoever to publish an app on the Appstore. I sought and found a method to be able to print at my home, directly from a SB program, using one of my PC's and the laserprinter. And i communicated that (simple) solution in full to other interested SB programmers.
That's all.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
GeorgeMcGinn
Posts: 435
Joined: Sat Sep 10, 2016 6:37 am
My devices: IPad Pro 10.5in
IMac
Linux i386
Windows 7 & 10
Location: Venice, FL
Flag: United States of America
Contact:

Re: Printing reports

Post by GeorgeMcGinn »

I've downloaded it and looked at how you are accomplishing this, and since I have an iMac (I have a PC ordered and custom built, but haven't yet picked it up) I will try and get this to work on sale MAC system.
George McGinn
Computer Scientist/Cosmologist/Writer/Photographer
Member: IEEE, IEEE Computer Society
IEEE Sensors Council & IoT Technical Community
American Association for the Advancement of Science (AAAS)

User avatar
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: Canada
Contact:

Re: Printing reports

Post by rbytes »

I am just in the process of setting up the print server following Henk's steps. I downloaded Python 3.7 and created the printserver file using its editor. Very nice syntax assistance is built in. Then I opened the command prompt and typed "python iOS2print.py" at the prompt. Got this error - 'python' is not recognized as an internal or external command, operable program or batch file.

I will take a look in C:/Programs to see if python version 3.7 goes by a modified name. Meantime I was able to just run python from its icon, open the printserver file and run it inside python. It gave me the expected message "Print Server started...".

Next I need to check my Windows tablet's IP address. I am stuck at the moment because I am not connecting properly to the internet, and am getting a warning that I have an invalid IP address!! I can't reboot our router/modem to reassign it right now without interrupting my wife's video stream.

So I will set this project aside until I can get connected and discover the IP address. I should have the print server running sometime tomorrow.
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Printing reports

Post by Henko »

When using the command line, you must first change to the directory where Python was installed, or include the path in the "python ...." command.
Better still, make a .bat file and an icon shortcut to it

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Printing reports

Post by Henko »

I have installed Python and the webserver code ("iOS2print.py") in a subdirectory C:\Henk, then made a small .bat file :

CD \Henk
Python iOS2print.py

Saved that too in the same directory, and created a shortcit icon for it.

There is one peculiarity:
The method uses the local IP adress of the PC/Mac to send the string to be printed.
Depending on the make and/or the settings of the router, this local adress is assigned dynamically by the router, hence the IP adress changes from time to time. If the IP adress in the SB code does not match, the printing does not work.

For the time being, a temporary solution is to open a CMD window and issue the "ipconfig" command. The current IP adress of the PC is then displayed after "IPv4 adress: "

In the report printing routines in the program section ( https://kibernetik.pro/forum/viewtopic.php?f=20&t=2216 ) , this IP adress is present in the "eprt()" function:

def eprt(t$)
dim h$(3)
h$(1) = "content-type:text/html"
h$(2) = "content-length:"&len(t$)
HTTP "192.168.2.5" HEADER h$ POST t$ ' IP adress of PC
end def

There might be a solution in which the adress of the PC is fetched by either the SB function or by the Python webserver code. I have insufficient knowledge about that.
Anybody here on the forum? (Otherwise i have to bother my son again😁)

User avatar
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: Canada
Contact:

Re: Printing reports

Post by rbytes »

All is well. My wife finished watching her video, I rebooted my router/modem, and my PC tablet reconnected to the internet. Everything worked, after i fixed two typos I made while transcribing the python program. :shock:

I have two nicely-printed pages now, and can see exactly how many lines (49 including title) and characters (83) fit on a page. I guess "regel" means "line" in Dutch?

I found that the most convenient way for me to start the print server program on Windows 10 was to create a shortcut for it on the desktop and drag it onto the taskbar. It is then accessible from either the desktop or the tile screen.

Thanks for sharing this information, Henk, and also give my thanks to your son. You two have certainly convinced me that computer wizardry is a family trait! 8-)
The only thing that gets me down is gravity...

User avatar
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: Canada
Contact:

Re: Printing reports

Post by rbytes »

I wrote a bit of SB code that would read a text file and send it to the print server. I used your test program as a guide. All you need to do is specify your own text file as fname$. See the code at the end of this post.

But there was an issue that I spent half an hour trying to solve. "Lyrics.txt" was text copied from a lyrics website. I stored it in the Notes app on my iPad. Somewhere it picked up some invisible characters that blocked the carriage returns and line feeds from working properly. Here is what I got from my printer. :?

2BB8BF43-2C89-460A-9078-E8EED7C5F6D9.jpeg
2BB8BF43-2C89-460A-9078-E8EED7C5F6D9.jpeg (1.45 MiB) Viewed 3013 times
I tried saving the s$ output string as a file on its own. Surprise. Even after I commented out the CHR$(13) and CHR$(10) characters appended to each line, there was still something causing line feeds to appear in the output file. So I realized that invisible characters must be hidden at the end of every line!

My solution was to put the cursor at the start of each line of my source .txt file, backspace to the previous line and backspace once more to delete the last character on that line. Then retype that character and press Return. That did the trick. Whatever was hiding in that space was eliminated. The final result:

F76023A8-4A89-4516-8C10-BF27505FF8B1.jpeg
F76023A8-4A89-4516-8C10-BF27505FF8B1.jpeg (1.13 MiB) Viewed 3012 times

Code: Select all

OPTION BASE 1
URL$="192.168.14.87"   ' use the URL of your PC
DIM h$(2)

' load a text file and prepare it for printing
fname$="Lyrics.txt"
fname2$="output.txt"
s$=""
FILE fname$ SETPOS 0
WHILE NOT FILE_END(fname$)
  FILE fname$ READLINE temp$
  s$&=temp$&CHR$(13)&CHR$(10)
ENDWHILE

' uncomment the next three code lines to check what 
' content the program is sending to the print server
'IF FILE_EXISTS(fname2$) THEN FILE fname2$ DELETE
'FILE fname2$ SETPOS 0
'FILE fname2$ WRITELINE s$

h$(1) = "content-type:text/html"   ' make header info
h$(2) = "content-length:" & LEN(s$)

HTTP URL$ HEADER H$ POST s$   ' send doc to the webserver

END
The only thing that gets me down is gravity...

Post Reply