PDF javascript info resources - javascript

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,

Related

Download page as PPT in JavaScript

I am planning to create a React frontend which handles HTML presentations. Besides letting the users present online, they should also be able to download their HTML presentation as PPT (like Google Slides).
I have not yet decided on what package to use for creating the presentations, but most of the packages seem to only support the typical print-download (the PDF that is converted from the HTML when you press cmd/ctrl + P). One exception is PptxGen, but that package is not an option for me (because of reasons not related to this question).
Is there a way for me to download a HTML page to PPT?
(There are multiple ways to download html to PDF - jsPDF being one. If it's cumbersome to download html as PPT, perhaps it's possible to converting html -> PDF -> PPT and then download it? Any advice?)
Thanks in advance!
Even after extensive searching, I did not find any other open-source library that handles direct HTML-to-PPT conversions, apart from PptxGenJS, so we can conclude that if you want a direct conversion, that's your only option.
There are some other ways to do this though, one that you mentioned is converting to PDF, then to PPT. I have found a service that can do both conversions, called Cloudmersive. They seem to have a free tier, and a Javascript API client that you can use from your frontend, so this is probably worth giving a try. If this managed service also doesn't suit your needs for any reason, you can still handle the conversions yourself, for example, with jsPDF and
pdf-officegen.

Pdf files editing and saving in browser

The scenario is that I have several editable pdfs that need to be displayed edited and saved all in a web based application.
I know this question has been asked before but I'd like to review the options. I work as a junior developer and I am being asked to research this. I don't think its possible as the pdfs are opened and viewed in different browser plugins that my code doesn't have access to but I still would like to know for sure before I report back to my superior. Is there any way I can tap into some API that allows for editing and saving on a webpage?
you could try this :-
A general-purpose, web standards-based platform for parsing and rendering PDFs
https://mozilla.github.io/pdf.js/

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.

Adobe Reader plugin interaction through 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

what are the ways to insert javascript to an existing pdf file (via API)

I was trying to find out any entries in the Adobe's API giving functionality of injecting javascript into the pdf file, but I couldn't find anything. I saw that there are few open source libraries that do that, but I'd like to focus on Adobe's SDK (C/C++).
Are there any ways to achieve this?
Thanks.
Certainly, as you've discovered you can find a third party PDF library that will let you insert JavaScript into PDFs or you can use Adobe's PDF library SDK. You'll find all of the info that you need in the Acrobat Developer Center. There is also this useful article: Introduction to Acrobat JavaScript.

Categories