Can you do file input/output using Javascript without using ActiveX, submitting a form to a server, or other extensions?
The reason I ask is after hearing all about HTML5 I thought I might take the time to find out what all the hype is about but I can't see any way to create regular applications.
An example of what I thought I might be able to do would be to create a simple text editor in the browser using only HTML5 and Javascript, where I can open and save files from the disk. After that I was thinking to try and create some kind of icon editor using the canvas tag. But without any kind of file IO each example is rather pointless (in my opinion that is). So, is this possible? And if so how would I go about doing it?
Thank you!
Yes. See this Mozilla demo which extracts EXIF data from a local image. The W3C is developing an API.
Related
I have a node web app that needs to convert a docx file into pdf (using client side resources only and no plugins). I've found a possible solution by converting my docx into HTML using docxjs and then HTML to PDF using jspdf (docx->HTML->PDF).
This solution could make it but I encountered several issues especially with rendering. I know that docxjs doesn't keep the same rendering in HTML as the docx file so it is a problem...
So my question is do you know any free module/solution that could directly do the job without going through HTML (I'm open to odt as a source as well)? If not, what would you advise me to do?
Thanks
As you already know there is no ready-to-use and open libs for this.. You just can't get good results with available variants. My suggesition is:
Use third party API. Like https://market.mashape.com/convertapi/word2pdf-1#!documentation
Create your own service for this purpose. If you have such ability, I suggest to create a small server on node.js (I bet you know how to do this). You can use Libreoffice as a good converter with good render quality like this:
libreoffice -headless -invisible -convert-to pdf {$file_name} -outdir /www-disk/
Don't forget that this is usually takes a lot of time, do not block the request-answer flow: use separate process for each convert operation.
And the last thing. Libreoffice is not very lightweight but it has good quality. You can also find notable unoconv tool.
As of January 2019, there is docx-wasm, which works in node and performs the conversion locally where node is installed. Proprietary but freemium.
It appears that even after three years ncohen had not found an answer. It was also unclear if it had to be a free (as in dollars) solution.
The original requirements were:
using client side resources only and no plugins
Do you mean you don't want server side conversion? Right, I would like my app to be totally autonomous.
Since all the other answers/comments only offered server side component solutions, which the author clearly stated was not what they wanted, here is a proposed answer.
The company I work for has had this solution for a few years now, that can convert DOCX (not odt yet) files to PDF completely in the browser, with no server side component required. This currently uses either asm.js/PNaCl/WASM depending on the exact browser being used.
https://www.pdftron.com/samples/web/samples/viewing/viewing/
Open an office file using the demo above, and you will see no server communication. Everything is done client side. This demo works on mobile browsers also.
I would like to implement an in-browser Microsoft Word document merge feature that will convert the merged document into PDF and offer it to the user for download. I would like to this process to be supported in Google Chrome and Firefox. Here is how I would like it to work:
Client-side JavaScript obtains the Word template document in docx format, either from a server, or by asking the user for a file upload (which it can then read using the FileReader API)
The JavaScript uses its local data structures (e.g., data lists it has obtained via Ajax) to expand the template into a document. It can do this either directly, by unzipping the docx file and processing its contents, or using DOCx.js. The template expansion is just a matter of substituting template variables with values obtained from the local data structures.
The JavaScript then converts the expanded template into PDF.
The JavaScript offers the PDF file to the user for download, e.g., using Downloadify.
The difficulty I am having is in step 3. My understanding (based on all the Googling I have done so far) is that I have the following options:
Require that the local machine is a Windows machine, and invoke Word on it, to convert to PDF. This can be done using a little bit of scripting using WScript.shell, and it looks doable with Internet Explorer. But based on what I have read, it doesn't look like I can call WScript.shell from within either Chrome or Firefox, because of their security constraints.
I am open to trying Silverlight to do the conversion, but I have not found enough documentation on how to do this. Ideally, if I used Silverlight, I would like to write the Silverlight code in JavaScript, because (a) I don't know much CSharp, and (b) I think it would be much easier in JavaScript.
Create a web service that will convert a given docx file to a pdf file, and invoke that service via Ajax. I would rather not do this, if possible, for a few reasons: (a) I tried using docx4java (I am a reasonably skilled Java programmer) but the conversion process is far too slow, and it does not preserve document content very well; and (b) I would like to avoid a call out to the network, to avoid security issues. It does seem possible to write a little service on a Windows server for doing the conversion, and if there is no other good option, I might go that route.
If I have been unclear about anything, please let me know. I would appreciate your ideas and feedback.
I love command line tools.
Load the doc to your server and use LibreOffice to convert it to PDF via the command line
soffice.exe --headless --convert-to pdf --outdir E:\Docs\Out E:\Docs\In\a.doc
You can display a progress bar to the user and when complete give them the option to download the doc.
More info on LibreOffice's command line parameters go here
Done.
Old old question now, but for anyone who stumbles across this, web assembly (wasm) now makes this sort of approach possible.
We've just released https://www.npmjs.com/package/#nativedocuments/docx-wasm which can perform the conversion locally.
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!
What is the best way to save a file from internet on javascript and/or C and/or even C++?
I saw this same question for C# and Java, but nothing to this three languages, so here is the question.
Hey, not so easy. The url point to some http://xx.xxxx.com/p.php?pid=staticetctectc....
I guess is php code which produce a nice gif in my browser. I just want to save this gif. Without opening browser. It is possible to do with javascript/C/C++?
Most near answer I found is this.
Thanks in any advice.
You can easily do this with JavaScript using Node.js. Here is a link to an example: http://www.hacksparrow.com/using-node-js-to-download-files.html
You could also do it from the command line using wget or curl. They are both available on pretty much every platform you can imagine.
For C++, you could do it like in Downloading File in Qt From URL. If you do not want to depend on Qt, libcurl is also an option.
For JavaScript, the method described in File Download Using JavaScript should work.
I am extracting content from a web page using JS/JQuery and want to write the data to a comma separated file. I know javascript doesn't really support file io and I'm trying to avoid setting up a local apache server just to process the content to a file. Is there an easier way to do this?
You can have your JS create the file text in a string. Then open a new window and write the string into the new window.
You can write a Mozilla Extension.
PROs:
You can use JS/JQuery on the extension
You can write files on the extension
CONs:
You can only use the application in Firefox (or any other Mozilla based browser).
There is no simple way of doing this. W3C has recently published the first draft of a File API that will make it possible, but it'll be a while until this is through and widely implemented.
Still requires a webserver, but you could build a small one method web service that your js calls, then the service can write out the data.