Observation: XoJo makes printing harder than it should be

It seems that you have to jump through hoops with way too many commands to print some simple text. In the old says, you wanted to print something, you just used the appropriate command and options to send text to the printer.

In XoJo, to print the current contact info in an app I’ve been working on, it took over 20 commands just to print 10 lines of information. That includes the printer setup. When wanting to just output lines of text to the printer, seems ridiculous to need to tell each string the position to print.

I did get it working, but just a pain.

I decided to be able to print all or a subset of records in the file to output to a text file, open the text file in the default text editor and print from there. This works just fine and I’ll stick with it unless/until I find a simpler and more intuitive way to do it all in XoJo.

Well, there’s reporting and there’s printing. But in general I think both of them are harder than they need to be in Xojo.

5 Likes

Reporting/printing, and the tooling for it, are clearly places needing a deep design from square one, and one entire year of dedication to make it perfect for Xojo.

Xojo report writer was always considered useless for most users, due to bugs and lack of features. I must say that I, as many of us, abandoned any initiative to make it work years ago, and I’m not aware on how useful it is today, because it looked abandoned by Xojo itself for years. I guess it still not useful today because people wrote their own engines, as Shorts, and DBReport (that I think that is now defunct).

1 Like

Yeah, printing sucks in Xojo. I miss the old Printer object in VB. This days I am sending some data directly to the printer with declares in windows.

For your case, maybe just create a class MyPrinter with a String array, add a Method “AddContact” or simply push the contact info to the array.
Then add a Method “PrintAll”, do the complex work there to call al the printing in a loop for each string in the array.

Then when you want to print just create a new instance, add the contacts and call PrintAll

That doesn’t really address the issue of ridiculously complex code to print a string or line of text. No thanks.

In this dropbox is a sample project that probably does all you need, from Tim Hare
It sends simple letters to the print spooler in Windows.

2 Likes

I perhaps have it a bit easier. Since I either receive HTML or plain text from the external source, I can easily convert the latter to HTML and then just use an HTMLViewer for printing.

3 Likes

i’m from the “print using html” team. super simple and multiplatform.

Thanks Jeff, I’ll take a look.

That is something I’d not thought of. I’ll have to give that a try! :slight_smile:

@Jeff_Tullin thanks for resurrecting that link. I haven’t touched it in years, but I’m happy to answer any questions about it. Printing is a big deal for us and was an issue when we started with Xojo until we wrote a set of classes to handle it and then it wasn’t. The raw print project was a one-off answer to handle sending escape codes to a label printer. I’m very happy with the page-as-a-canvas approach that Xojo uses. It gives us a great deal of flexibility, in my opinion.

I don’t deny that a quick and dirty printer.writeline mechanism would be nice.

1 Like

It sure would, after the suggestions to use the HTMLViewer, I ran with that and it’s working beautifully for what I’m doing!

2 Likes

That is a question I was asking (to myself) recently.

I do not have a single idea to how to do that.

Hints ?

In the VB6 era, printing was mostly done on line printers (dotmatrix), hence the very simple writeline.

Today, line printers are a vintage rarity, and most every printer is page oriented. Hence the need to create a printer object and print graphically to it.

Progress…

Based on suggestions from others to use the HTMLViewer, I just wrote my data out to a text file and then read it in to an HTMLViewer where with one command, you can print everything in the HTMLVeiwer, no fuss, no muss!

With a tiny bit more work, I formatted the text file as an HTML file, and I was able to use HTML tags to do things like selectively Bold Text, etc. Far easier than using the other methods. And once again, one line of code to send contents of the HTMLViewer to the printer.

4 Likes

Progress and printer capability, absolutely! Progress with using it in XoJo, no so much.

If most of us here liked doing the things the hard way, we’d be using C++ or Assembly Language, instead of XoJo. The whole purpose behind products like XoJo (aside from the cross platform support) is to make like easier with visual design and useful built in methods so the programmer doesn’t have to reinvent the wheel so they can focus on what they really want to do.

Obviously with the responses from others, I’m not alone in the frustration of how printing is done in XoJo. The suggestions by others to use the HTMLViewer is brilliant! You simply let it handle all the complexities of printing with a single command. Writing to a text file and opening with an HTMLViewer is quick and easy and works great! And using HTML for formatting, also makes it easier.

The only caveat I can see there is that, if you’re all-in on the new Desktop Controls, the new HTMLViewer does not offer the native rendering option on Windows (which still works on Windows 11, at least on an upgraded system.) Unless you stick with the old control, you wind up with a built app that could weigh more than half as much as Firefox. :slight_smile:

I’ve stopped trying to use HTMLViewer for that reason, despite several people saying ‘size isnt important’

1 Like

I’m using an HTMLViewer anyway so I’m already getting the bloat.

2 Likes