kanc3lamistrad Posted February 10, 2012 Share Posted February 10, 2012 Dear all, This is my first post on this thread, and I really hope I could receive some help from you. I am trying to search for a line code that could download a web page as a PDF. On my site, I managed to put a javascript function to print a web page with “window.print()”, but I don’t know how to save it as a PDF. The code for printing web page is: <script type="text/javascript">window.print();</script> Can you please help me save a page as PDF with a javascript function? Thank you in advance,Alex Link to comment Share on other sites More sharing options...
ShadowMage Posted February 10, 2012 Share Posted February 10, 2012 AFAIK, there are no functions in JavaScript that allow you download, save, or print a file in any format other than the format it's already in. In other words, JavaScript can't convert files to different types. PHP can generate PDF files using certain libraries, like FPDF. I think that's about your only option. Link to comment Share on other sites More sharing options...
kanc3lamistrad Posted February 12, 2012 Author Share Posted February 12, 2012 Thank you for your answer. If I cannot save a page as PDF, is there any code that I can use to save page as it is (for example, page.html)? I have tried <script type="text/javascript">window.save();</script>, but it seems not to be working. Thank you in advance! Link to comment Share on other sites More sharing options...
Ingolme Posted February 12, 2012 Share Posted February 12, 2012 There is no Javascript function for that. You have to tell the user to go to their browser's menu and save it manually. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 13, 2012 Share Posted February 13, 2012 Guess I should have been a little more general. JavaScript does not have access to local file systems. That's a security risk. It may be able to read certain files, but it certainly cannot create or save files. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.