Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do advanced printing from a web application?

I have been researching options for printing report-like data via a web application. Some options that are viable are writing PDFs, Excel XML, dumping HTML to Excel, or using a tool like activePDF webGrabber. I suppose the question is, what are some solution that give control over print from a browser (IE in my case) yet doesn't have a huge development time. Though I don't have experience with it myself, I have seen some horrid code for generating PDFs.

The features I'm looking for in particular are to print landscape or portrait without user intervention. Also, having control over basic styling is important to translate the basic look/feel of the web app to the printed format.

Any advice (especially from experience) is appreciated.

like image 698
oglester Avatar asked Oct 23 '08 23:10

oglester


People also ask

How do I print from Web application?

Web applications can print to local printers installed on your device using the browser print function which is accessible by pressing the Ctrl+P keys. Without using the browser's print function, web application cannot access printers on your device.

What is a print service ArcGIS?

A print service is used to print and preview maps from the Print button in Map Viewer and Map Viewer Classic, and from print widgets in apps created using ArcGIS apps, such as Web AppBuilder and Instant Apps.


2 Answers

As I've asked about here already and found out the hard way, you aren't going to get reliable and accurate printing results purely within the browser. Even if it is an intranet application that you've been promised must only work with IE7, IE8 will be out soon and then Firefox will be allowed and all of your careful micromanagement of CSS will be for naught (do I sound bitter?).

The most forward looking solution is to bite the bullet and go for generating PDFs. The tools you mentioned are good. You should also look at iText and iTextSharp. Once you get the hang of it, doing the PDF layouts isn't any harder than HTML and CSS and you will know that the results will print correctly on everyone's computer, everyone's browser, and everyone's printer. I'm currently working with iTextSharp (not finished yet, but still learning and experimenting).

I haven't found reliable ways to control the print options from within a page either, so relying on your users to change from portrait to landscape or to set or adjust margins or turn off the print headers and footers just doesn't work in the long run - you'll end up annoying them and creating more headaches for yourself when they can't (or just don't) follow instructions.

The "Related Questions" sidebar is very useful. I saw these questions on controlling the printer from the web page (both with answers that amount to: "you can't"):

Programmatically Selecting Landscape Printing

Printing to a Specific Printer

like image 74
CMPalmer Avatar answered Oct 10 '22 16:10

CMPalmer


You can also look at setting up specific CSS stylesheets for printing. What's nice about this is you can take an exiting web page that is displayed to the user, change the formatting slightly to remove any fancy banners or other ink hogging type images, and then print out what they see on the screen.

Some sites will have a link to a "printer friendly version", but even having a reference to both the display and the print stylesheet in the HTML header will work if the user decides to simply hit CTRL+P on the page they are on.

like image 39
Dillie-O Avatar answered Oct 10 '22 17:10

Dillie-O