How to print? Examples?

I am lost on how to print information in a web app. In the example I can see it is using prewritten html. The information I have to print is generated based on what is in the database and I cant really use prewritten html. Does anyone have an example of a method to print? Maybe an example of how to write the html in a way to generate something that looks like a report? Ive been able to make everything in web 2.0 work but half the program I am bringing over is financial reports. It’s a dealbreaker. Hoping to do this without plugins as well. Thanks for any help!

Have you considered generating PDF documents for download? https://documentation.xojo.com/api/pdf/pdfdocument.html

1 Like

Yes. Im going to add that in at some point but our existing desktop app, which were are making the next version into a web app needs to print directly.

I’m not sure what you’re printing, but I based mine around a RowSet (I even have a Method that turns a ListBox/WebListBox into a RowSet!). I then have a Method that turns any RowSet into XLSX/CSV/tab-delimited or PDF.

With the PDF I first have another Method that turns any RowSet into HTML, then I can convert that to PDF using wkHTML2PDF.

All of this works on both desktop and web apps, and gives me identical PDF exports for all platforms.

I’m not sure about your users, but I would have thought that if you export as PDF and not print directly, most users would be happy with this.

Your Xojo code, running on the server, cannot print directly to the user’s printer. You need to create a web page that displays the way you want it, that the user can then print from his browser. It’s a bit of a pain, but that’s how the web works.

You should be able to trigger the user’s browser to bring up the print preview dialog for the current page with something like:

ExecuteJavaScript( "window.print();" )