0

I have an HTML "printer friendly version" type page that I'd like to convert to a document-style file type so that I don't have to worry about disabling links on the page and stuff. Is there a fairly simple way to create a file like that from the page's html without using third party libraries?

At first glance this is going to probably look like a duplicate of a bunch of other questions, but most of the answers involve using third party software, which isn't an option for me.

tereško
  • 58,060
  • 25
  • 98
  • 150
Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67
  • Most OS have the ability to print to pdf... – dotjoe May 11 '12 at 15:51
  • But thats not really the issue. The issue is that if I just display the printer friendly version page as straight html, all of the links and stuff from the page are going to be clickable (although broken). To fix that, I'd like the page to be displayed as a pdf, or xps, or something – Phillip Schmidt May 11 '12 at 15:54
  • 1
    Why not fix the printer friendly page so that it doesn't have (broken) links and let users print it however they like? I'm not aware of non-3rd party library way of generating pdf... – dotjoe May 11 '12 at 16:24

2 Answers2

2

If you're talking about an asp.net site, you don't have the HTML that is given to the browser; you'll have to do whatever you want to do to generate a PDF and send that back to the browser. You can't let ASP.NET send HTML back to the browser and expect the user to see PDF...

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • But i have the HTML from the page that *calls* the print preview function, which I am creating the new html from. Then, I want to convert that new html to pdf – Phillip Schmidt May 11 '12 at 17:15
  • 1
    You're calling that on the client computer; you have no idea if they have a print-to-pdf driver on their computer... – Peter Ritchie May 11 '12 at 17:21
  • You guys are clearly not getting the point. I just want to display the page as a pdf. Then they can print it to whatever they want. – Phillip Schmidt May 14 '12 at 13:44
  • You've missed the point, the only thing you can do is send the HTML to the browser. If you want to send a PDF to the browser *you* have to send the PDF... – Peter Ritchie May 14 '12 at 14:25
  • And that's what I want to do. – Phillip Schmidt May 14 '12 at 15:03
  • Your question was how to get HTML passed to the browser to be "printed " (e.g. print preview) as PDF. If you just want to send PDF to the browser, use something like http://itextsharp.sourceforge.net/. See also http://stackoverflow.com/questions/465433/creating-pdf-files-at-runtime-in-c-sharp – Peter Ritchie May 14 '12 at 15:06
  • i.e. unless you write the code to generate a PDF, you have to use a 3rd party tool – Peter Ritchie May 14 '12 at 15:07
  • I guess the question wasn't clear enough. Yeah, what I really wanted to do is send the pdf to the browser, just because I'd rather have them seeing PDF then a "real" page which doesn't work. There are telerik grids on the page that are clickable and have animations and all that kind of stuff, and it didn't make sense to me for a print-friendly page to be interactive. But I think what Im just going to do is something like: – Phillip Schmidt May 14 '12 at 15:11
  • and then CSS the underlines away and stuff – Phillip Schmidt May 14 '12 at 15:21
0

I just did it with CSS. Sorry I have to accept this as an answer, but the only answer posted wasn't really what I was looking for..

Phillip Schmidt
  • 8,805
  • 3
  • 43
  • 67
  • @PeterSmith said "Is there a fairly simple way to create a file like that from the page's html without using third party libraries?" and claimed he has achieved it. How did he do, I wonder? "I just did it with CSS" is somewhat a vague answer. – marquito Jul 03 '12 at 15:54
  • @marquito if I knew how to do it the right way, I wouldn't have asked the question, right? Would you have rathered I post all of the relevant CSS? It's just CSS to style links more like text and hide buttons, etc. My CSS isn't going to help anyone anywhere, so I answered the way I did. Thanks for the not-so-constructive criticism, though. And by the way, its `@PhillipSchmidt`, not `@PeterSmith`. – Phillip Schmidt Jul 03 '12 at 18:03
  • No need to put up a fight, @PhillipSchmidt. I didn't ask for the **CSS code** itself, but thought you missed the point of marking it as an answer as you did not actually answer your own question. I was more in hope of finding an answer than criticizing you. Sorry. (I would edit the post to change your username but there's no means to do it except deleting it) – marquito Jul 03 '12 at 21:08