Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to implement a button that will allow users to save a pdf copy of an html page. I know they can go through the 'print' interface, and select the 'save as pdf' option, but I'd rather have my button automatically select that option so that it automatically selects the option 'save as pdf' (or better yet, goes straight to the pdf download).
Is there a way to do this in javascript?
The "Save to PDF" button in the print dialog doesn't exist in Windows afaik.
Anyway, there's no way you can do this with Javascript.
If you really want to give your visitors a PDF download of your page, you need to render that PDF on the server side and link the button to the PDF file.
Why don't you just link the button to a script that converts the page to a PDF. You can either use your own server script to convert the page to PDF or use a save as PDF link to a service like HTM2PDF.
It's not clear in both cases why you would need to utilize JavaScript at all. But if you're really keen on using JavaScript I believe there's something like a 'headless webkit' in JavaScript by the name of PhantomJS.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I explain my problem to you:
When I do PHP curls on some site or want to display the source code of the page element is missing a lot. I think some part is called by a script or something. Could someone help me view the entire code with Curl PHP.
To duplicate my problem go to Facebook or LinkedIn and right click on the page and "View the source code of the page", in this you don't see all the page content but when for example you right click and "inspect an element" You can.
Thank you in advance
CURL can't do this. It's not designed to render HTML or execute JavaScript.
A lot of the content on Facebook, LinkedIn, Twitter and many other pages is loaded through different ways. (like fetch()-requests or WebSocket-Events)
Some nodes you can see in the inspector are not part of the original document (which you are viewing with "view source" or curl downloads). What you see on the inspector is everything currently held in memory, which was partially (or completely) created with a scripting language.
This is basically done to
reduce the load on servers as it doesn't have to generate the whole page on every request
reduce traffic on clients and servers (no need to reload the header-data and/or scripts over and over again)
If you need data from a rendered site, you should either check if the website provides an API which gives you the data you are looking for or use one of the cli-rendering-engines from this answer.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
When I go to others' page, I want to see the Javascript code how others write.
Can I view the js code by right click and inspect (chrome) , I know html and css can be seen, but how about js code?
Open up your browser developer tools and go to the Network tab, then load a page. Select the "Type" column, and then you can examine those with a Type of script. For example, on Stack Overflow, you'll see something like:
As you can see, Stack Exchange loads jQuery, a script named stub.en.js, a script named clc.min.js, and a few more. To see what those scripts contain, either click on them in the Network tab, or right-click and select "Open in new tab" to view it as a standalone tab.
But professional sites often minify their Javascript, and complicated minified Javascript is very difficult to read. Better to read source code whenever possible, not distribution code, to save yourself a headache.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I want to save web page directly to PDF.
What I have done is-
<form>
<input type=button name=print value="Print" onClick="window.print()">
</form>
But it gives me option for print or save the page as PDF.
But what I want is when I click on the button, it directly save the page as PDF not showing any option.
Is there any solution in JavaScript?
Thanks in advance for helping.
The short answer is no, you cannot prevent users from seeing the option in their browser using just javascript.
The slightly-longer answer, is that you can do this with a bit more than javascript.
Using a service such as html2canvas, you can send a POST request to a page on your server. Use that page to convert the image to a PDF, and have it output the file as a download.
Assuming you're using PHP:
<?php
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='screen-shot.pdf'");
// The above headers will cause the file to automatically be downloaded.
// Use a library to convert the image to a PDF here.
An example library to convert an image to a PDF is mPDF, or TCPDF. Feel free to Google others, especially if you're not using PHP.
Do note that this solution is inferior to them just making the choice themselves, as the quality definitely won't be as nice.
Must notice here that the suggested solution converts HTML into image and then the raster image is converted into PDF.
If you want to save into PDF that is searchable (so can be archived and printed with best quality) and the text is printed clearly then you should consider one of these options:
Ask user to save the page into PDF by providing instruction to do so for Google Chrome or Safari (both browsers are able to "print" page into PDF files). Maybe you may even try to show this instruction and invoke the printing dialog
Use some of client side javascript libraries to generate PDF from the data with the tool like jsPDF (free, open source) or similar
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to create page turner effect for PDF files with angular? Jquery solutions are also fine. I have seen turn.js which uses html. Can any one help out to find a way for PDF files?
If you are talking about the pages within a PDF having a page curl effect then it is not something you can do with js, html or anything else outside the PDF itself without converting the PDF to something else (ie flash, jpg images, etc).
Last time I checked the only way to achieve this within a PDF was by using Acrobat Pro or InDesign and using 'Page Transitions'.
Please note that out of the available page transitions 'Page Turn' (the curl effect you want) will cause the document to be converted to a flash file and then embedded in the PDF.
I'm sorry if this is not what you want to hear. Rather than creating fancy page curl/turn effects it is probably better to concentrate on producing a well designed, easy to navigate document with great content. This will provide much better value.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I create an online file editor?
My web application will allow a user to create a new text file, edit it and save it. He can do so with multiple files open in multiple tabs.
If these are only txt files then;
Choose the file store to use. Either store the files in a db or on the file system.
Then all you need to do it load in the file and render it within a textarea and save that back to the file. You may want to keep copies for backup purposes and undo or something.
If you want the file to have nice colors etc then consider a jQuery editor like tinymce.
If however you want to edit any type of doc like word, excel then i think you'll need to use the office object model. but that won't help you with other formats.
As for the tabs, there are heaps of jQuery tab controls out there that will do exactly what you're looking for.
Check out https://bespin.mozillalabs.com/
It is open source.