How to Print PDF through javascript without using iframes - javascript

I want to print a PDF when a button is clicked through javascript. i don't want to use iframes.
Can any one help me?

If your user doesn't have a PDF printer driver, you'd have to use something like this:
http://badassjs.com/post/708922912/pdf-js-create-pdfs-in-javascript
or perhaps a PDF webservice like one of these:
http://blog.nitropdf.com/index.php/2008/01/23/free-online-web-services-to-create-view-share-and-edit-pdf-files/

Related

jQuery/Javascript Create PDF from HTML/CSS with selectable text

I'm trying to convert a web page content into a PDF and I've successfully done it with jsPDF + html2canvas and with html2pdf but the problem with both approaches are that they convert the content into an image and then generate the PDF off the image and I need the PDF content to be "selectable" because I need to pass certain tags that will be read by another application.
so far I haven't found anything that would allow me to do this with jquery/javascript.
Any ideas how to accomplish this?
Thanks in advance,

Print another page, but stay on the current one

I have an invoice system made in PHP. There is a view with all customer's invoices. I'd like to make an option to print an invoice.
I know about window.print() and media="print" for CSS. But I was thinking, is it possible to just print an invoice by clicking a button next to it, but staying on the list page? It would just open a printing prompt with different content and do nothing to the current experience.
I thought of a workaround. On click, I could just replace contents of some element with invoice's data and make the styles hide everything else besides that container. That looks like a trick to me though. Is there any other solution to that problem? Perhaps something like download attribute for links:
Download Me
That could be something like:
<a href="invoice.php?id=3" print>Print Me</a>
Or perhaps an HTTP header? Please share some advices.
I would suggest to use JQuery PrintJS plugin below:
http://printjs.crabbly.com/
This will ultimately solve your problem.

Convert HTML to PDF with links

Is there a node.js module or a javascript library that can convert HTML/Page into PDF with selectable texts and working links? I've tried Phantomjs. But since its the only screenshot the page and convert it to pdf, texts are not selectable and links are not working. Also tried jsPDF but links are not working either. Hope you guys can share some of your experience in dealing the same problem.
Your response is greatly appreciated.
You can parse the HTML body with htmlparser. The complete html will be properly converted to JSON.
Depending upon the keys, you can then write it to a PDF using pdfkit.
This is very general solution. If you give us an insight as to what type of HTML you want to get into a PDF, maybe then we would be able to help with some specific code or logic.
Try http://www.cloudformatter.com/css2pdf.
Their links demo at http://www.cloudformatter.com/CSS2Pdf.Demos.Hyperlinks shows external links and internal links within the generated PDF.

how to embed a pdf from a url using pdf.js

I've googled alot but I can't find an answer to this simple question, I just want to do something like
embed_using_pdf.js url="http://freeexampapers.com/index.php/directory/download?location=A%20Level/Accounting/Edexcel/2006%20Jan/9944774_Question%20Paper.pdf"
and I get a pdf inside my page
btw, this is a force download link, that's why I don't want to use an iframe or an object.

Using PDF as a data entry mechanism

I was working on converting PDF to HTML but the client wouldn't have it. So here we go. I need a way to tell an inlined pdf form to submit POST to a url. Something or other like:
<!-- Inlined PDF -->
<object type="application/pdf" data="http://xxxxxxx" id="pdf_form">
</object>
<!-- Button I add to the page to do a form submit -->
<input type="button" onclick="javascript: DoSubmit();">
<script type="text/javascript">
// Do a POST with the form data here. Either getting the data out of the pdf
// or using ACROBAT's FDF export & http submit to handle this
function DoSubmit() {
// Get 'pdf_form' and tell it to post it's data to a url
}
</script>
I need it to work this way to the client doesn't have to add a submit button to the pdf whenever they want to add a new form. I'm trying to make the system pretty flexible for adding these forms in; because there are a lot of them.
Best bet is if I don't need to modify the pdfs manually to get this working.
There's also a toolbar that comes up that includes a save button on it. Removing that save button or making that save button do a form submit rather than a pdf file save is also important.
I have good news and I have bad news.
Let's start with the good news as there is fewer of that: You can use JavaScript in PDF just like you can use JavaScript in HTML.
The bad news:
you'll need adapt your PDF to establish a communication between the JavaScript in the PDF and the JavaScript in the HTML. Take a look at an excerpt of my book to find out how to do this. From the HTML, you can trigger a method postMessage(), but this message will only be understood by the PDF if the PDF contains a MessageHandler.
It's a known issue that this doesn't work on every OS (last time I checked, it didn't work on MacOS).
Adobe Reader shows a toolbar that allows people to save a PDF. There is no way to remove that toolbar. I've already answered this question on stackoverflow: Can I hide the Adobe floating toolbar when showing a PDF in browser? Note that the other answer refers to 'Open Parameters'. As far as I know, these parameters can make the upper toolbar in the plug-in visible/invisible, but they have no effect on the 'floating toolbar'.

Categories