Save Web page directly to PDF using JS [closed] - javascript

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

Related

Image generation on a webpage [closed]

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 2 years ago.
Improve this question
I'm developing a webpage that displays output from a numerical model that I am running. I'm looking to take user input (latitude/longitude coordinates specifically), use php or something similar to call a python script which takes these coordinates as input and produces a png image, and then show the resultant png back to the user.
Is there any framework or anything to do this? I'm mainly looking for pointers on displaying the image to the user.
This is how you could display an image after a form has been submitted using javascript.
<body id="body">
<!-- Add a form to take in latitude/longitude coordinates here -->
<button onclick = "addImage()"> Click to Generate Image</button>
<script>
function addImage() {
//Call function here to generate image from form imput
var img = document.createElement('img');
//insert path to generated image below
img.src = 'https://source.unsplash.com/xJsE87_f78s';
document.getElementById('body').appendChild(img);
}
</script>
</body>
I think the google map library has every you want in it, you should check it out https://developers.google.com/maps/documentation/javascript/tutorial. gl.
I would recommend Yii2 (Yii2 Framework). It is very easy to use and fast enough to setup and understand. They have an easy introductory tutorial and with that you can create a webpage that allows users to login in and, after being logged in, to post a form with the coordinates that you can manipulate in php and python to show the image.
The thing is that you would need to learn some basic knowledge in VMC architecture (View, Model, Controller) while learning about the framework, which would take at least 1-3 weeks. But it would help you a lot for any web future project.

creating Page turner effect for PDF files with angular JS [closed]

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.

Javascript 'Print' button straight to 'Save as PDF' [closed]

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.

Is there a good web application for manipulating pdf files? [closed]

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 7 years ago.
Improve this question
Is there a good web application for manipulating a PDF files? For example, drag and drop images to it and save for future reference, then remove the dropped images anytime etc. I want to integrate it with my existing web application also.
EDIT:
These links I have came across while searching. Might be useful for someone searching the same.:)
PDFescape
Crocodoc
A.nnotate.com(a.nnotate.com)
GroupDocs Annotation(groupdocs.com/apps/annotation)
Mozilla has pdf.js which renders PDF files using HTML5. This same script is used in the built-in PDF reader of recent Firefox browsers.
It's experimental, but you could hack the code and do whatever you want with it.
If you are looking for just an online tool which will spit the pdf file use - Sejda
there is a lot of other tools available online too
PDF Sharp will allow you to do all sort of manipulation that you require. It is open source, free to use. You can download it from here..
Features include
Creates PDF documents on the fly from any .Net language
Easy to understand object model to compose documents
One source code for drawing on a PDF page as well as in a window or on the printer
Modify, merge, and split existing PDF files
Images with transparency (color mask, monochrome mask, alpha mask)
Newly designed from scratch and written entirely in C#
The graphical classes go well with .Net

How to create a QR code reader in a HTML5 website? [closed]

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 5 years ago.
Improve this question
I was looking for possibility to create QR code reader in my HTML5 based web page. I've done some googling and all the links point me to the mobile applications.
Please help me with some pointers as to how I can use HTML5 and JavaScript to read a QR code containing a url and then redirect the browser to that URL.
There aren't many JavaScript decoders.
There is one at http://www.webqr.com/index.html
The easiest way is to run ZXing or similar on your server. You can then POST the image and get the decoded result back in the response.
The jsqrcode library by Lazarsoft is now working perfectly using just HTML5, i.e. getUserMedia (WebRTC). You can find it on GitHub.
I also found a great fork which is much simplified. Just one file (plus jQuery) and one call of a method: see html5-qrcode on GitHub.
Reader they show at http://www.webqr.com/index.html works like a charm, but literaly, you need the one on the webpage, the github version it's really hard to make it work, however, it is possible. The best way to go is reverse-engineer the example shown at the webpage.
However, to edit and get the full potential out of it, it's not so easy. At some point I may post the stripped-down reverse-engineered QR reader, but in the meantime have some fun hacking the code.
Happy coding.
The algorithm that drives http://www.webqr.com is a JavaScript implementation of https://github.com/LazarSoft/jsqrcode. I haven't tried how reliable it is yet, but that's certainly the easier plug-and-play solution (client- or server-side) out of the two.

Categories