views:

1853

answers:

9

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.

+2  A: 

You could have a look at SQL Server Reporting Services. There are also a number of third party reporting tools like http://www.devexpress.com/Products/NET/Reporting/

Craig
+4  A: 

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.

Dillie-O
This is the correct approach unless you are looking for very accurate and repeatable print layouts, like forms or anywhere you need to align the results. He also asked about user-selectable portrait or landscape and this route requires the user to adjust their print setup, which is a sketchy idea.
CMPalmer
See this: http://stackoverflow.com/questions/37162/how-do-i-make-an-html-page-print-in-landscape-when-the-user-selects-print
CMPalmer
+1  A: 

I'm not sure if this is what you are looking for but why not just use CSS with a media=print style sheet. Design your style sheet so that the printed form has the characteristics that you want. Alternatively, you can do export to Excel by downloading data in CSV format and letting the user construct their own reports from the data.

For actual PDF and Excel I've used controls from Aspose.com.

tvanfosson
If the data is tabular, the export to Excel option is excellent. No matter how you present your data, someone else will want to slice, dice, color code, and graph something from it - letting them download Excel (or just CSV) allows for all of that.
CMPalmer
Yeah, but my CEO doesn't like that. He prefers the report prints after he click the 'print' button.
Salamander2007
+9  A: 

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

CMPalmer
Just an upvote and comment to say iTextSharp is GREAT. I've used that too with much success.
Dillie-O
Actually I find Firefox 3 to do stuff much better than IE. Firefox 2 did suck big time though.
Milan Babuškov
+3  A: 

I have used and had luck with iTextSharp in a C# application. It takes a bit of work but if you have graphics experience it all makes sense and the PDF can look really good (and print well).

http://itextsharp.sourceforge.net/

If you want the code to generate PDF not to horrid, just make sure to write nice PDF code! For example write really modular code with lots of in-memory classes that you combine (like Lego) to represent the objects that will go on the PDF. These objects would just need to know how to draw themselves to PDF.

Jared Updike
+1  A: 

Works for IE only:

http://www.meadroid.com/scriptx/index.asp

Absolute control for those who need to print html documents from client and server computers running Microsoft's Internet Explorer browser.

A basic subset of ScriptX printing functionality -- header & footer settings, printed orientation, coarse control of margins and a browser window/frame printing command -- is available at no charge, and is freely distributable. Advanced printing functionality is not free. ScriptX-enabled documents need to refer to a valid publishing license in order for advanced printing to work.

jeremib
+1  A: 

Seconding what others have said, you are just never going to get the browser to print like you want. Speaking from experience, the print media type CSS looks like it'll work, but it really never gets the job done - especially if you need to work in more than one browser (and since I'm including multiple versions of IE as different browsers, I think all web sites end up needing to be.)

I think the best way really is to dynamically build PDFs on the fly. Find a PDF package you like / can afford for your platform and run with it. Trust me, you'll be glad you did.

Electrons_Ahoy
A: 

It depends on whether your expected client base is known or unknown. If you want to allow 'anyone' to generate printable documents, then I concur with others that the PDF route is a good one to go down.

We've had good success using PDFLib to easily create attractive PDF documents. Using their server side modules you can have a designer create your document in InDesign or Illustrator, then programattically drop in the dynamic fields on top (even using Acrobat to place the fields)

It's a little trickier for reports and dynamic row data, but can be done.

For actually printing - if you're creating an application when your user base is known (eg. an office environment) you might consider an label printing application like BarTender. You can either have the web server call print jobs via an API or have the BarTender application poll the app for new jobs. Handy for web applications where you want to hit 'Print' on the site and have the printer start printing (no other user intervention) as the server is actually doing the printing, not the client.

A: 

Mainly to share the way I dealt with this, but also to offer another option...

I was using a 3rd party grid that exported Excel XML. To make it work for me, I used XSLT and some code to tweak that XSLT in order inject the print settings. It is not as powerful as PDF I'm sure, but it was a pretty decent compromise that did not required much customization per page.

So, the solution in basic is to export in the Excel XML format and inject the tags for page orientations, scaling, and whatever else you might like. You can start with a basic Excel sheet and save as XML, making the tweaks you want. Then you read the source and figure out how Excel did it. I was not able to find any useful documentation.

Greg Ogle