views:

721

answers:

1

I'm building a calendar in ASP.NET using Jquery, And I'm trying to implement Print. I can print simple html or images with no problem. But I can't figure out how to build a print like google calendar print.

When you press Print in "Calendar Print Preview" the print dialog that pops up has more options (cross browsers), Some how this print dialog is different from a simple browser print, And they seem to have more control like setting landscape print for example.

Any one knows how to implement this?

Thanks

+2  A: 

It is just a popup window with some options which are posted to server-side script which generates a .pdf document.

You could use

<link media="print" rel="stylesheet" type="text/css" href="main.css" />

to do something similar without using serverside script which generates image/pdf.

Note the media="print", that means that given stylesheet is going to be used when you print the page. You can specify custom css rules (like hide navigation, make calendar look nice on paper, etc) there.

EDIT:

In response to comment. If you convert the html to pdf it will look exactly the same. When you submit that form in google calendar they take all those options and generate pdf from them. If you chose landscape, they will rotate the page and recalculate everything so that it fits the page. To simplify it for you, they draw an image on server-side according to the options you submit and put it into pdf.

It's not that simple if you haven't done it before. I would play around with css and JavaScript on that print page and see if I can mimic something like that by switching between landscape and portrait using JS and css rules (make 2 buttons - "landscape", "portrait", when user clicks on them you change css rules for your calendar so that it fits given paper size). Again if you are not familiar with css then it will be hard.

There is no definite answer, the path google took is very nice, but it's not that simple to reproduce.

More info in comments.

Maiku Mori
I'm copying the calendar html to a new window that has a window.print() button.So I need to convert html to pdf and print the pdf?Do you know how can I do this?And how can I control the pdf print, like setting landscape print?Thank.
SirMoreno
Updated answer.
Maiku Mori
Thank you for the answer.I've checked the css option and I didn't find a way to set landscape print, (you can only change the style).
SirMoreno
Well you can't change page orientation with css. What I proposed is changing calendar css rules so that it take a form of landscape document or portrait one. Then user can just print the page. If you are searching a way to print landscape document, it's under printer setup from print menu in your browser.
Maiku Mori
Also take a look at this http://stackoverflow.com/questions/37162/how-do-i-make-an-html-page-print-in-landscape-when-the-user-selects-print
Maiku Mori