How to print outputstream PDF using Javascript - javascript

I'm getting PDF file as output stream and want to print it using Javascript. There're some tips about printing PDF file or iframe. But I need to print PDF files that is generated by server after print request.

JavaScript can't access any local resources like the file system or attached printers, so this isn't possible directly.
What you need is to convert the PDF to, say, HTML5. Then display that in your browser and call document.print() to print it.
The project pdf.js already does a pretty good job to convert PDF to HTML.

Related

How can I get all the text in Chrome's PDF viewer in Javascript?

I am writing a Chrome extension that manipulates PDF files and am looking to get all the text of a PDF file that's currently open in Chrome's PDF viewer.
I learned from
How can I get selected text in pdf in Javascript?
how to get selected text, but I couldn't find in the API a function that extracts the entire text (or better yet the PDF itself, and then send it to a server). Is it possible?
I am aware of the solution of sending the URL and downloading it on the server side, but sometimes it is problematic (e.g. PDFs from password-protected websites).
Thanks.
I have tried looking in the API, https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/resources/pdf/pdf_scripting_api.ts
I have also tried "downloading" the PDF on client side and sending it as Blob to a server, but it's a problematic solution (sometimes blocked for example, requires extra permission).

Converted PDF should be saved on server side, not downloaded

The issue is that a converted PDF is downloaded by the client. I need the PDF to be saved on server side and sent by mail.
I am using jsPDF and html2canvas for converting HTML to PDF.
I guess that jsPDF is not the proper tool for your task. First line at Github is "Client-side JavaScript PDF generation for everyone" which says it all.
To let the server create a PDF, you need a tool which renders the HTML result and creates a PDF from it. Maybe a MS Word or OpenDocument template used in headless mode will suit your needs, as suggested here among other solutions.

Prevent PDF Download in PHP

Is there any way to prevent PDF download and printing option from browser ?
I am using PHP codeigniter for uploading the PDF file from admin side. I want to restrict the download access, inspect access, page source access from user side. Users only need to read the PDF.
So is there any way to do this using PHP or Javascript?
Users can take screenshots, which is not a problem. I only wan't to prevent the pdf url and download access in all aspects.
Do we have to convert PDF to any other format for this?

save a pdf and close it programatically

I am automataing a webbased application using Selenium Webdriver.
A report is generated in PDF format is opened Acrobat reader. I have to save that PDF to a specific location and then close the pdf. So how can it be done thru automation. I tried searching on net and found this can be done using VB script but then need Adobe professional version for the same. Also the report that is generated doesnot have a specific title. That keeps changing.
Can this be done using javascript ?
Thanks
It's possible to generate some PDF in JS, try http://snapshotmedia.co.uk/blog/jspdf
It will return you an base64 string or an URI. Then you can redirect your visitor to the PDF (with this URI) or write down the base64 in a file.

How to open local images from browser and display them at the center of the page?

I want my browser to open my local images and to place them at the center of my browser. The only way I could think of is by coding an HTML+CSS file, but I don't want to use PHP or ASP.NET cause I don't want to run a server. So javascript is a solution to this.
So, is there a way for an HTML+Javascript file to display a list of my local files, and after clicking at the image I want, the image name to be saved to a variable in order to display this image to my html with img src using the css style I want?
Thanks in advance!
This is only possible with some kind of special file system that is based on XML (I've seen this once)
You need to create a XML index file (or some other format you can get with XMLHTTP Web Requests and parse with JavaScript) that contains all information about the images (System location, maybe some kind of ID, alt/title attributes etc.)
Then you load that file with a XMLHTTP Request, parse the data and print it as HTML with correct links to the images.
JavaScript itself can't read the file system, it can request single files only
Accessing local filesystem from Javascript inside a browser is a pretty taboo thing mostly. See this related question.

Categories