Makes PDF readonly - javascript

I want to display PDF in Read-only format so website visitors can read PDF but not allowing them to download or print or any other operation.
Anybody have such reference code?

It is possible to disable the printing option in a PDF, this can be done by setting a password on the printing funtion and ofcourse not sharing the password.
If you google this you will find how to do this. This Website might already be a good start.
Note: you will need Acrobat Pro, wich is not free.
Keep in mind, like #Stephen already mentioned, people can make a screenshot or something similar and print it anyway.

That's not possible, and not very practical as well:
If you can view it in your browser, you already have downloaded the file.
If you have it in your browser, there's nothing that can stop you from printing a screen capture of the file, so even while it is possible to create a PDF that isn't printable, it would be easily defeated.

Related

Saving web page as pdf looking exactly the way it looks in browser

I have a web page that is dynamically generated by php. Sometimes I need to save that page to share processed data. I usually save it in Opera browser and it works perfectly fine. However some people may not have Opera or virtual printer installed. Is there a simple way to save page as pdf by JavaScript? Or maybe on the server side by PHP? I've been trying jsPDF, but it is terrible. It doesn't see fonts, it doesn't work with utf-8, it doesn't display css styles properly and generally you need to re-create that page from the scratch if you want decent result. I just need magical button Save that will do the same thing Opera does. Does such thing exist? If yes, where can I find it? If not, why?
You could use Phantom JS for that. http://phantomjs.org/screen-capture.html

How to make a HTML file auto savable?

I need to create a single html where the person can input text in text fields, then click a button and save the file itself, so he wont lose changes. The idea is similiar to what wysiwyg does to html documents, but I need that to be implemented on the doc itself.
Where do I start from? I can't find anything like that on Google, perhaps I'm searching the wrong therms.
Need something that uses HTML + Javascript, no server side scripting.
JavaScript alone does not have the ability to modify files on your file system. All browsers do this for (good) security reasons. You will not be able to make changes to the html document itself (but according to the comment by Sean below, you might be able to produce a new copy of the document).
You might try using cookies to store the input values (automatically write them and load them when the document opens). There are various jQuery plugins available to aide in reading and writing cookies.
In business or enterprise systems this is usually done with a database, which would require server-side scripting.
I think most of these answers are incorrect. Using the FileSystem API, content is only saved to a sandboxed hidden folder, the user has no control as to where it is saved.
As suggested by Sean Vieira, using TiddlyWiki is a good solution.
However, if you want to customise it, you can make a Flash/JS bridge in which the Flash SWF saves the actual content.

How can I simulate "CTRL +S" keypress in Javascript

I have a page with HTML/JavaScript code I want to export to an HTM file when the user presses the export button on the page. I basically just need to find a way to trigger Ctrl+S to execute the Save Page dialog window. I have searched all over and can't seem to find any thing for this that allows JavaScript to simulate that key press sequence.
TL:DR - Does anyone know how to simulate CTRL+S key press in JavaScript/jQuery
Use the saveDocument() method. Docs for it here.
Edit: That only works in Firefox.
I don't think Javascript can do that. There is something for printing but not for saving.
What you can do you create a hint for the browser that the file is an attachment.
You need to send some HTTP headers. You can for example do that with PHP:
header('Content-disposition: attachment');
Maybe .htaccess works also if you don't want to use PHP. You can look that up.
If you want the browser to save the user's page preserving changes in the DOM, this might be beyond the scope of JavaScript, which aims to provide interaction with the page itself, not the environment it's working in.
On some devices this might even be inapplicable - saving pages in Android browsers it not that straightforward and not always possible.
Still, if you're looking just for a working solution for several desktop browsers, you could look at TiddlyWiki, which is a kind of a "local wiki", content on which are kept client-side and saved with the page. Saving is implemented in Java (not JavaScript!) applet distributed with the page. Kind of a web-based browser-based application.

Writing to Text file using JS only

I need to write to a text file using JavaScript. I have a machine I need to run some HTML file on and it uses JS to manipulate content. I want to log the changes the user makes in a text file, and the computer does not have and will never have any server-side scripting language. So I just wanna know how to append text to a txt file using JS only. Alternatively, running a batch script upon JS call that will do the work itself, is a good equivalent, but I'm sure it's the same level of difficulty...
The script will work on an IE only machine, but I need to be able to test it on other browsers as well... So I'm not sure how and if ActiveX works on Chrome for example, but if it doesn't, I need another solution... Help please! :)
Not exactly the solution I was looking for, but I ended up using cookies, which limits the amount of data I can hold to very little, but beats nothing.
While there's some promise with the new File API, you'll probably need to go with a server-sided language for reliable file-writing.
Some possible alternatives are to 'write' the changes to the localStorage, or perhaps to create a URI download. There's plenty of tutorials online for setting these up. Good luck!

Using Celerity to download a file

I'm using Celerity in JRuby to automate the download of some .csv files from certain websites. For one of the websites (LinkShare), I've gotten very close but cannot figure out the last step.
The website pushes the file download using javascript and the 'hidden iframe' method - during regular browsing, when you click the download button, it calls javascript that creates a hidden iframe containing the download content, and the browser picks that up and prompts the user to save the file.
Obviously doesn't work quite the same way in Celerity. I can see the new iframe in jirb after I've clicked the link, but can't call any methods on it, getting errors like:
NoMethodError: undefined method `getDocumentElement' for #<Java::ComGargoylesoftwareHtmlunit::TextPage:0x184e6efc>
Anybody have enough experience with Celerity/Htmlunit/Javascript/Jruby that they can point me in the right direction? I just want to retrieve the download content (the .csv file).
Alternately, does anybody know of a (headless) browser automation tool that would be better suited for the task, if one exists?
The first thing I'd do is check that you're navigating to the frame. A frame (even an iframe) is treated as a completely separate window, and you'll have to navigate there first. Check the Celerity::Frames class.
Failing that, you may want to try a library that controls a browser, rather than emulate it. Libraries that emulate a browser (such as htmlunit and mechanize) have their limits, and you may have found one. For this, I'd recommend using watir/firewatir.
Mechanize may work for you, it's meant to more closely resemble a normal person's usage of a browser, while remaining headless.
http://mechanize.rubyforge.org/
As ehsanul said Mechanize might be a good starting point. You'll need to figure out the URL being accessed to retrieve the file. Also, look for a cookie or session ID identifying your session to the host. Mechanize should capture that and return it as that's part of what it does.

Categories