How to print PDF file from link opening modal box using javascript? - javascript

I'm using VueJS and I trying to print a PDF document file that I generated by a link, example: localhost:3000/file12.pdf
I was reading about window.print, but I did get open the file in other _blank page, instead of modal box that I would like.
I looking for some lib, find this PrintJS but I didnt find param to open a link. Anyone can suggest me how to do it?

Related

How to open a PDF document from a local or share drive in Angular 2

I have a Angular 2 application and need a button to open up a PDF document. This document is on a share drive so I don't think I need to download it. How can I achieve this in Angular 2 app? I tried window.open("file://F:\doc1.pdf"); this only opens a new tab in Chrome but nothing is displayed and in IE nothing is happening.
I also try using anchor tag (see below) in the html but still no luck. I can paste this link in a browser and it will bring up the doc.
Doc1

How can I programmatically save HTML/CSS as a PDF using javascript/jquery?

I'm using OS X and I see on chrome that I can Save as PDF in the print window if I set the destination to "Save as PDF". Does this functionality exist in Windows?
Is there any way I can take advantage of this and have it save to PDF with just a click of a button? How can I open up the print page and save that as a PDF? Can I set the default destination to "Save as PDF" and then programmatically click the "Save" button?
Edit: I have tried to use jsPDF but was unable to pull the CSS.
there is also an option to print PDF on Windows 10.
This javascript code opens a print dialog:
window.print();
I have used PhantomJS before to render PDFs from webpages programmatically. You'd have to write a PhantomJS script to accomplish that but they have helpful examples documented.
jsPDF is a good tool for this.
This question is a possible duplicate of Download a div in a HTML page as pdf using javascript, which provides a demo and sample usage for jsPDF.

Settings for Javascript window print

I would like to print my webpage as an pdf with the window.print(). Right now I just get the dialog box up as default. I was wondering if I could make it select print to pdf and then proceed by it self.
I have tried classes like dompdf etc., but this print to pdf is really what I need here. So if it is possible to set some default printing settings and maybe make it automatically, then let me know.
As mentioned in the comment no you cannot do this. Also not sure if you have custom print button or you are using Ctrl+P shortcut.
In cases you may see a PDF is opened in a new tab and you can download from there.
Otherwise in operations like bank account summary download , generally handled by a kind of form submit , and the pdf is created by controller/service layer by using PDF Generator like iText.
HERE is a link for information on PDF open source library.

Image button - print a document from my webpage

I have a website, but I need a button which I want to print a specific .pdf file from my webpage database.
As an example, this site
has a print button, which gives you option to print some pdf files
Any idea how can I do that?
I've tried this one, but it's not working:
<a href="../Documents/ScrittoGraffito/Scritto_Customers/Nicolaides_Optical/Nicolaides_webpage/Shop1_Banner.pdf"
onclick="window.print()"/><p class="test">link</p></a>
That code will tell the browser to open the print dialog for the current page.
If you want to force the browser to print the linked pdf then that is not possible, as it will be completely controlled by the application or plugin that handles pdf documents.
EDIT;
Apparently it is possible, but you have to make use of a pdf toolkit.

print a pdf via javascript

I have a HTML page that has a link to a PDF. This PDF opens in a new window.
The parent HTML page has a File->Print menu item. When the user clicks Print I want to be able to automatically open the PDF and print it. The printing part is where I am stuck.
Any help would be much appreciated.
Thanks.
If you open that window with a specific name (e.g. target="nameofwin") in the link pointing at the PDF, you might get away with nameofwin.print(). However, I'm not sure if that'd work since the PDF will be shown using a plugin, and not be a native part of the page. There may be some API that allows you to interface with the PDF display plugin, but then you're stuck wondering if you've got Acrobat or FoxIt or WhateverElse running in there.
You can probably use PDF.js to render the PDF in a hidden div. Then, on your "print" button, register a click in which you add a new print stylesheet to the document, show that div, print the window and then remove the print stylesheet.

Categories

Resources