Printing a PDF document from a browser - javascript

I have web application that dynamically generates XHTML. The XHTML is then converted to PDF using Flying Saucer. The document is then streamed to the browser and served inline.
Part of the requirement is to automatically print the generated PDF without user intervention and then closing it. I have never come across such a feature before. Can I print the PDF from a web page using JavaScript? considering I don't have a physical file location!!
Any thoughts on how to tackle this issue would be appreciated

Related

Force a browser to download an BIG HTML file to disk and open it

Task:
I have a huge html file that is placed on server, I want to show it to the user by click of an URL.
Issue:
As this file is huge, On click of the URL the browser doesn't render the page in time*(Records get appended continuously while the vertical scroll bar size diminishes, user is not able to do anything but see the first few records)* and the default spinner of the browser spins endlessly.
Can this be achieve this way, if yes, how?---> On click of the "link", the html file should get downloaded on client machine first, then viewed on client browser window from his local system not from URL directly(maybe in a iframe or something).
EDIT
loading 500 MB of HTML was asking a lot of a browser.
Work around
Since generated htmls files were huge, we converted htmls files to pdf format. Later, used browser's default pdf viewer capability to view the data on browser window itself or simply downloaded the pdf file onto the disk.
No, there is no way to force a browser to download an HTML file to disk and open it.
In practical terms, a 500+ MB HTML file will never be readable -- loading it requires much more memory than is available to a web browser. Downloading it won't help. You need to break it up into smaller documents.

How to stop print to file in browser?

I am developing a web application which is displaying pdf files in web browser and i want to put restrictions on printing this document.Is there any way to stop printing to file as i need to print through physical printer only.
Since PDF can be downloaded to computer and than opened with any PDF reader, it means you can't prevent certain functionality of ALL readers.
You still can have your own interface that allows or disallows some functions, but I think printing to file is also browser stuff that can't be controlled using JS.
go through css3 media queries in MDN. You must find print media type in the page. It has some restrictions on page printing. https://developer.mozilla.org/en-US/docs/Web/CSS/#media or https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Media

ways to open large-sized pdf without downloading (using open on javascript)

Good day,
I have a system that renders large amount of data through pdf ( 30mb + ). Now I want the user to view pdf first so he can either download it or just print it right away. as of the moment I am forcing the user to download the file since open( 'datauri here' ) wont work with larger files.. the problem with downloading is that files are multiplying and consumes space over time and also its not necessary for me to download all files that that they want to print right away.
I need a functionality that is similar to chrome's preview when using windows.print
can you please suggest any ideas or other things to do this?
I am currently using javascript library to create pdf (pdfmake). I am also using chrome as my main browser
You would have to make sure that the PDF is optimized for fast web view, and that your server is using the byteserving protocol for serving the file.
If that is the case, a useful PDF viewer (such as the web browser component provided by Acrobat/Reader) understands this protocol and requests (after the first page plus overhead of the PDF) only the data for the pages which are to be displayed.
A quick search did, however, not reveal whether the Chrome PDF viewing component is smart enough to understand the byteserving protocol.

How to convert a single page webapp into an offline format

I created a single page application using AngularJS. Is there a way to automatically convert it to an offline format like pdf or chm? The website contains multimedia content such as webms and ideally those should be preserved. Although having a single file (like a chm), would be preferable it would be sufficient to be able to view the contents of the website locally without having to use a web server.
Solutions like saving webpage as MHTML, HTML Help Workshop and WEB to CHM don't generate useful output. Allowing users to download the website and open the files directly doesn't work because of this error.

Need a print button in a browser that will print a PDF file

I need to set up a print button in HTML that will print a certain PDF file, hopefully without having to download the file first. I've tried a few things but some only work in IE. and some require downloading the file as an embedded object which also is not acceptable. Embedding javascript in the PDF sounds the most promising, but I'd rather avoid that if possible for other reasons.
Any other ideas?
Unfortunately it really can't be done... PDFs are not handled naively by any browser, and as is such they can't be printed using the browser's print dialog.
Your users will have to download the pdf and print it with whatever PDF software they use (Even if it's just a plugin for the browser) unless you convert it to boring old html or an image or something.
You cannot print something without the user downloading it first.
The printer is located on the user end of the connection. The PDF is, at first, located on the server end.
The PDF must thus travel across the webs to reach the user end before the printer will know which ink to put on paper. In other words, it must be downloaded.
I think the best you can do is download the PDF into an iframe element, and advise the user to click the "print" button in there. To my knowledge, no tighter integration than that is possible. The PDF viewer's print button can not be accessed via JavaScript.

Categories