Adobe Reader plugin interaction through Javascript - javascript

I'm displaying PDF file that are generated on-the-fly within a ASP page. The PDF generation (and download to the client) can take some time and I'd like to provide the user with some feedback (a loading message or something).
AFAIK there's no way to know when the PDF is viewed because the DOM events get triggered when the Adobe Reader plugin gets loaded (even though it's not displaying anything yet).
I noticed that there's a Javascript API for the plugin object that I could potentially use. I notivced a LoadFile method on it but unfortunately it doesn't seem to do much.
Adobe's documentation is really useless. It talks of Javascript only as a plug-in writting language or as OLE interaction (and poorly).
Is there any documentation for the API and is it possible to know when the PDF has been loaded? It would be perfect if I could pass on a PDF stream to a PDF viewer of some sort.

I've wanted to the same, found a page that may help you out.
http://www.adobe.com/devnet/acrobat/javascript.html

Related

PDF javascript info resources

My goal is to create a "dynamic" PDF. Basically the wanted functionality is
Calculations
Open another PDF from the same origin
Usage monitor (notification when opened or performed something)
Submitform
I found JavaScript could be embedded in a PDF but the functionality is limited and depends greatly on the viewer.
I looked at some Adobe docs (PDF reference, JavaScript for Acrobat API Reference, Developing Acrobat Applications Using JavaScript & Acrobat JavaScript Scripting Guide) and was able to build a PDF that performed more or less as I wanted in Adobe Acrobat but when opened in Firefox (PDF.js) or Chromium (PDFium) almost nothing worked.
Before asking a specific technical question I would first like to really understand what is possible so I'm able to judge if JavaScript is an option. So any reference to good resources to increase my insight/knowledge in/of this topic would be really appropriated.
To be clear my question is NOT related to PDF generation via JavaScript but related to embedding JavaScript code inside the PDF to make it more dynamic.
Many thanks in advance.
Best regards,

force window.print() to download a PDF

I made a feature for my website to let my users download the content of the site using these instructions: Printing with Javascript || Mozilla Dev. Basically the user is printing a new formated site stored in a hidden iframe. Now I want to let the user download that same PDF by clicking a button. Is there any easy way? I'm very happy with the result of window.print().
I've taken a look a jsPDF but it doesn't seem to be rendering my CSS correctly. Aditinally this library is pretty messy and hardly documented, I had to digg into the code, and I can't get it to work properly.
There's no way to do it reliably client-side. You could use PhantomJS or similar server-side to handle PDF generation.
If it were me, I'd just let the users do it themselves. Chrome, for example, has a virtual printer driver which exports as a PDF. For everyone else, there are print drivers available that do the same thing, such as CutePDF.

Access PDF.js Viewer functions / events

I am looking into putting together a small site that reads a few PDF files and loads them in the PDF.js viewer. (I want to use the viewer specifically) I still want all of the viewer UI and functionality present, just adding a sidebar with a list of files to chose from.
Alas I have not been able to really understand the PDF.js code (or a lot of the Viewer.js code provided for that matter)
Currently I am looking for a way to pass the PDF.js viewer a new file to open. (Without reloading the page and using the url parameter)
With that said that is only the bare minimum functionality to continue with this project.
I am also looking for something that can resemble a function reference for any of the Viewer / PDF.js functions that can be used for interactions:
I/O of the files
moving through pages / headings
scaling the pdf
any event triggers
I haven't been able to find anything direct from Mozzila's Github Wiki. And the recent tutorials that I have been able to find don't make use of the Viewer at all.
To open a file from a url:
PDFView.open(url, 0);
Set page:
PDFView.page = 2;
zoom/scale:
PDFView.zoomIn(10);
PDFView.zoomOut(10);
Basically just look at the PDFView object in viewer.js.

Async file upload in IE 9 and 10 only

Objective
I am creating a web application and have been looking for an async file upload solution other than iframe and form support.
Browser Support
I am fully willing to exclude everything but IE9+. IE tends to be the browser I have the most trouble with.
Goal
I have a table and I want to be able to click on a link, show a file dialog and then upload the file immediately after selection. No page refresh.
More specifically I am trying to figure out how Trello does their file uploads. After looking through the javascript, I found that they bind the the file input to an on change listener, but after that I can't see what they are doing. Im under the impression that they use websockets with node.js to transfer data, but after doing a little research, most people say that websockets wouldn't be good for that. Trello blocks all versions of IE except 9 and 10 so I looked into HTML5 File upload think that may be a solution. However, after some research IE9 does not support the HTML5 File API.
Question
So finally I am looking for some way to upload files without the iframe and form solution. Can someone list the possible methods I could use?
Sidenote
I am using Rails for backend and Ember.js for front end.
If the browser does not support the File API and XMLHttpRequest level 2, there is no other way to upload files in an async/"ajaxy" manner other than reverting to the hidden iframe method. You could, of course, use Flash or Java, but neither of those (especially Java) seem like a good solution to me.
Regardless of the browser, you will have to include a file input element on the page if you want to provide a file chooser for the user. The onchange listener you speak of is vital to determining when the user has actually selected a file or files. In browsers that support the File API, you can also allow users to drop files they wish to upload onto your page. This behavior alone does not require a file input element.
IE9 and older do not support the File API.
I'm quite familiar with this territory as I maintain a fairly popular javascript-only upload library: Fine Uploader.

In-browser conversion of MS Word document to PDF

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.

Categories