 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 30th, 2004, 02:57 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Output content to .pdf
I've run up against a "printable version" of my page issue, and one of the possible solutions a coworker mentioned was outputting the page to Acrobat Reader. Of course, he was lacking on details but it sounded intriguing. Has anyone done this?
I have output to Excel many times using Response.ContentType. Mayhaps this is a similar process.
- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
|
|

September 30th, 2004, 03:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
I don't think there is built-in support for PDF in .NET. Also, simply changing the content type to PDF won't work. PDF has quite a unique document structure that you need to create to make this work.
For classic ASP there are many components available that can generate PDF. One of them is ActivePDF ( www.activepdf.com). Not sure if there is a .NET version, but you can always use COM Interop to make it work when all else fails.
Search Google for PDF components; there may be better, easier or cheaper components available as well.
Cheers,
Imar
|
|

September 30th, 2004, 03:13 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Oh, P.S. If a printable version is all you need, there are many cool ways to do this with CSS. What "issues" did you run into? Maybe this can be fixed without third party stuff.
A well designed page can be made printer friendly without third party components and without even a second version of the page.
This way, when users just hit the default Print button, the page will still print as designed.
Let me know if this is still an option, and I'll elaborate a bit if necessary.
Cheers,
Imar
|
|

October 1st, 2004, 07:33 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well the main issue is the width of the page. It is a report and the width can vary from report to report. Generally, they will be wider than the browser will print.
I was surprised that the browser (IE6) doesn't have a "Shrink to fit" option and that it will cut off the printout if it is too wide. Also FYI this is an internal system - everyone will be using IE.
In would like to hear your ideas on printable versions.
- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
|
|

October 1st, 2004, 09:12 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Imar,
I am dealing with a printing issue myself- specifically in making sure the page break doesn't happen in the middle of a sentance.. I'd love to hear your solution to this!.
Hal Levy
I am here to help you, not do it for you.
|
|

October 1st, 2004, 12:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
For starters, take a look at this (limited) FAQ: http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=240
It discusses the media="print" attribute to a style sheet <link> tag. Using media="print" allows you to use a different style sheet for a printed version of your page. While you're on the FAQ page, try a Print Preview. You'll notice the logo, menu and other navigational elements have disappeared and at the bottom of the page an additional box with a description of the article has appeared. This is all done with a separate style sheet.
One of the first things you need to do is limited the width of page. Wrap your entire page in a <div> and then use the style sheet for print to limit the width to, say 600px, or better yet, 100% so it fills the sheet of paper.
Next thing to do is hide the things you don't need. Using display: none; will hide specific elements, as I have done with the menu and logo.
You can do a reversed version of this to show elements on print only, by setting display: none; in the main style sheet and display: block; in your print sheet.
Another thing you can use is page-break-before and page-break-after to force a page break at specific places.
You can also force the paper orientation (landscape or portrait).
Hal, maybe you can use page-break-inside to avoid page breaks within a paragraph. Haven't used this before, so I don't know whether it will work or not.
One other way it might work is like this, but it requires JavaScript and not CSS only:
1. Define a strict height and width of the page you want to print.
2. Load your content in a <div> and then use the DOM to measure the height of your <div> tag with the content.
3. If it is too high, cut of the text at an appropriate location.
I think this is an awful lot of work, and may not be worth it. Hopefully the page-break-inside can do the trick.
I am not sure if this is even possible with a PDF component. I know Word processors can do this with the "keep lines together" option, but I am not sure how other technologies deal with this.
Further reading for those interested in printing from the Web:
http://www.alistapart.com/articles/goingtoprint/
http://www.w3.org/TR/REC-CSS2/page.html
http://www.w3.org/TR/2003/WD-css-print-20030813/
Cheers,
Imar
|
|

October 1st, 2004, 01:33 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
If you have Visual Studio with Crystal Reports installed, you can output this to a .pdf file. You might want to look into that option.
J
|
|

October 1st, 2004, 01:38 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have been looking into the style="PAGE-BREAK-AFTER: always" solution, but I found that this does not work with absolutely positioned elements, which I use in my pages. :(
- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
|
|

October 1st, 2004, 01:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Follow up: I did a quick test with page-break-inside. It has the desired behavior in that it will force an entire (block) element to the next page when the section is about to be split over two pages. But guess what: it doesn't work in IE 6. It works fine in Firefox, so maybe I just discovered yet another reason to switch to Firefox as the preferred browser ;)
The PDF option with Crystal Reports is a nice solution as well; didn't think about that earlier...
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Casta Diva (Bellini) by Maria Callas (Track 16 from the album: Maria Callas: The Voice Within the Heart) What's This?
|
|

October 1st, 2004, 01:49 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can't you override the positioning of the elements in the print style sheet?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Casta Diva (Bellini) by Maria Callas (Track 16 from the album: Maria Callas: The Voice Within the Heart) What's This?
|
|
 |