JavaScript: Save PDF in the 'Microsoft PDF reader' - javascript

my web app opens a PDF inside an Iframe. Users can then add texts, draw with digital ink and highlight text. As the PDF is rendered using the user's browser-engine, I recommend trying it with the latest Microsoft Edge.
I would like to save the edited PDF to the location I opened it from with the click of a button.
The PDF editor of the browser has a save feature, but users have to select the location first, and confirm that they are overwriting the file.
Is it even possible because Microsoft Edge seems to isolate the PDF process. When I open a PDF in Edge without my web app, I can simply click the save button, and it will be saved at the location I opened it.
I could not find any documentation for microsoft pdf editor and how to interact with it.
Full code of my project: https://github.com/joseftogo/PDF-Notes-Manager-Alpha
Thank you!

I agree with KJ's opinion. When you open a pdf on a website in Edge, you're actually view it online. So it's wrong to say "save the edited PDF to the location I opened it", it's not opened from local file path. If you want to save it, you're not overwriting any file on your computer, you're downloading a new file to your computer, so you have to select the location first. It's the necessary process.
For the situation you say, "When I open a PDF in Edge without my web app, I can simply click the save button, and it will be saved at the location I opened it." I think that's when you open a local pdf file in Edge. At that time, Edge is just a viewer, and the pdf is already existed on your computer so of course you can overwrite that file directly.

Related

Get Firefox PDF viewer information

I have a web application written in c# that shows pdf documents.
What I do is when a user click a document, I open a new browser tab and show the pdf.
Everything works fine but in Firefox i have a boring problem.
If the PDF viewing option is set to 'Preview in Firefox' goes fine, otherwise the browser downloads the aspx page where the document should be shown.
Is it possible via javascript or c# code know what option is set and so manage the situation in a proper way?

Save PDF when clicked on a download button without showing the OK/Cancel option to save

Is it possible not to show Open/Save dialog? I would like to save the pdf file straight to specific disk location on client PC. Need in NOdeJS
I am automating a LogIn in NodeJS which after a successful login, on clicking a 'Download Report' should download the pdf directly to the computer. On manually testing it does so. However when i run my script after clicking the 'Download Report' it would give a javascript popup for confirmation to save. –
EDIT: After reading your comment again, I noticed you are adding some settings to your profile that sound like they should make it do what you want. Since it isn't working, I think it would be good for you to try what I describe below.
END EDIT
You stated in a comment that you are using Selenium Webdriver to do the login automatically, and the download popup only appears when Selenium is driving the browser. The reason it doesn't keep your settings (to not show the popup) when Selenium is in control, is that Selenium creates a new profile, which has the default settings. You will need to manually create a profile for your browser (I see you are using Firefox), open Firefox with that profile, change the settings to not display the download popup, and tell Selenium to use that profile when it runs.
I'm not sure what your environment is, but I run Selenium from linux, so to create a new profile, I run Firefox from the command line with a -P flag, which opens the profile manager. If you use windows, you may need to look up another way to do this.
Once you have the profile created, and have changed the settings appropriately, change your code to the following:
FirefoxProfile profile = new FirefoxProfile(new File("path/of/firefox/profile"));
Hopefully that will work for you.

JavaScript Phonegap open PDF file

How to open PDF file without plugin?
I'm tried : window.open(path, '_blank', 'fullscreen=yes');
and opened blank page in editor.
Do you want the PDF to open inside your app, or is it OK if it's opened externally? If it's the latter:
On iOS you can just create a normal link with target="_blank" and Phonegap will open the pdf in Safari.
On Android you need to call window.open with "_system" as window name: window.open("yoururl", "_system", "location=no"); and Android will either open in the browser or start downloading (which might not be very obvious), or show the "Complete action using"-dialog if there are several options to open the file.
Of course, the downside of opening externally is that the users need to get back to your app themselves after viewing the PDF, so if you anticipate many users will view the pdf I would not recommend this solution.

Precache file with Javascript in the browser?

How can I do this:
the page loads
javascript loads a remote PDF file into local memory
the user clicks a button/link
the system launches the PDF reader or starts a download dialog with the PDF file already in memory
In other words, it's a regular file download in the browser EXCEPT that the file has already been loading in the background in order to speed up its receipt when/if the user decides to download the file.
You would have to encode the file (perhaps via a servlet), then you could get it through an XHR, and write it into a data uri, which you could then attach to a button or link.
This technique would probably only work on small files and very recent browsers.
StackOverflow won't let me post an example link as a link, so to test the concept, you'll have to copy the following line into an html file and see if you can load the link:
pdf link
This worked perfectly in Chrome when I tested it just now, and worked partially in Firefox. It didn't work at all in my version of IE.
Another potential solution is to make absolutely sure that the pdf is being cached, and then try to load it in a hidden iframe. Whether this works or not will depend on how the user has their browser set up.
You should consider not doing it at all, given the difficulties.

How do you get a spreadsheet to open Excel instead of a browser window?

If you call javascript window.open and pass a url to a .xls file it open on some machines in the browser window. How can you force it into Excel?
Only the users machine can "force" it into Excel. That said, 99% of the time if you send the correct mime-type and a user has Excel, then it will open in Excel assuming they approve.
And only the server can send the correct mime-type. The document type you pass to a JavaScript window.open call will have no effect on this. In fact, calling window.open will at best just open a superfluous window.
It's best to just link to the document with <a href="foo.xls">. And provided your server is sending a mime-type of application/x-excel or application/x-msexcel this will almost always nudge the browser into opening a new window with the Excel document.
If it's just a static file, and you're using Apache on Linux, check for a file called /etc/mime.types, and ensure that it has the following line in there to associate the .xls file extension with the correct MIME type:
application/vnd.ms-excel xls
I'm guessing the location of that file might vary across systems, but it's in /etc/mime.types on my server which is running RHEL4.
AFAIK you can't do this with JavaScript alone. If you have some sort of scripting language on the server's side you can alter the header to force a download.
Here's a simple tutorial in PHP, but you can easily find one in your favorite language.
You cannot force it into Excel. You can allow the browser to handle it whichever way it is configured to do so, or you can try to force it to download the file and let the user open if from their desktop. To force a download, search for "force download" and your server-side language (PHP, ASP.NET, JSP, etc.)
I don't think you can: you cannot call external programs using Javascript for security reasons. Assuming that the user has Excel installed, you may want to open the new window without the address bar to give the user "the illusion" that the file has been opened with Excel in Internet Explorer.
I wouldn't think this is possible from javascript due to security issues, there would be nothing stopping a rogue webpage from opening dozens of excel/word instances.
Could you not set a hyperlink to the url of the .xls, that way the user would get the usual download prompt to view the file.
Set the http content type to the Excel datatype: application/vnd.ms-excel
You shouldn't need to redirect to a new window, but you will get a popup asking the user to save or open the file.
In relation to (2): I'd worry if a browser could launch an external application and load data into it automatically without user intervention.
This is a setting in each user's browser and not in something that can be set by code. So unfortunately you do not have control of that.
You can not, as it depends on the client machine.
For example on Windows if you want it to always open it with Excel, not in the browser window, you have to open My Computer, Tools, Folder Options, File Types, select the XLS type, and click on Advanced. There are two checkboxes: Browse in same window and Open web documents in place. Uncheck both, close browser window, open it again and try again.
However as I said: it depends on the client, you can not force it.
You can do this using LaunchinIE, an ActiveX Control that will enable HTML pages to start whatever application on the client's machine, without security warnings.
Quote from the site: "At last, web pages can start Word, Excel, or any other corporate application without complaints. Securely."
For this you do have to install the control on the user machine and also add the URL that is allowed to execute local applications to the Windows registry.
Another quote from the site: "To ensure security, LaunchinIE needs to be carefully configured client-side; due to this restriction it's only fit for intranet use."
I use LaunchinIE in our training facility so I can use Internet Explorer as a menu which lets the user choose the machine setup. LaunchinIE then calls a batch script that configures the machine to best support the selected training.
Here are the steps to get this pop-up back when opening a saved Excel file.
Right-Click on the windows [START] button and select Explore to open Windows Explorer window will open.
From the menu select Tools \ Folder Options…
• Choose the File Types tab and scroll down the list of files.
• Left-Click to highlight the XLS Microsoft Excel Worksheet file extension and click on the Advanced button.
In the Edit File Type window, Uncheck the “Browse in same window” option.
Click OK button to accept your changes.
Start a new browser session. The next time you open your Excel spreadsheet in your Inbox, you should be prompted with the following window. Be sure to leave the “Always ask before opening this type of file” as checked. Clicking the Open button should now open your file in Excel.

Categories