Adobe JavaScript in HTML: Step ZERO - javascript

I am trying to start learning Adobe JavaScript and use it in HTML. I downloaded the Acrobat JavaScript Scripting Guide and Reference to help me with the code but I don't know where to put that code. I wish it can be something I put in a web browser.
I don't think I can simply embed a pdf in my HTML and use JavaScript to refer to it because the manual says:
HTML JavaScript cannot access PDF
elements, only Acrobat JavaScript
can
(I am not sure though)
Now what should I do to use Acrobat JavaScript in HTML (how to include the code)?

JavaScript code requires a host application to execute. The host application has a JavaScript engine which will execute JavaScript code in documents that the host application is fed.
The JavaScript engine in a browser will execute JavaScript code in a web page. A
PDF viewer or plugin will execute Javascript code inside a PDF document.
The JavaScript code in a web page cannot interact with the JavaScript code in a PDF document and vice versa, as they are executed by different JavaScript engines.

The execution environment for Acrobat JavaScript is within a PDF. Some PDF viewers other than Acrobat/Reader support this object model to some degree or another, but for the Real Deal, you need an Adobe PDF program.
You can download a free trial of Acrobat Pro from adobe.com, that'll get you started.
Once you have Acrobat Pro, open up any old PDF, add a button to it (NOT with LiveCycle Designer),
Edit that button's actions (last tab)
I suggest you pick the mouse-up event (the default), though there are several others to choose from.
You then select the action type "Run A JavaScript", you'll have to scroll down a bit.. and click "add"
Type your JS into the resulting JS editing window. Their JS editor is Weak.
Start typing.
Close the editor, and close the button properties.
click on the button (with the hand tool, like a normal user)
Check the JS console for where you went wrong. ;) ctrl+j to bring it up.
You can also type script directly into the JS console and hit ctrl+enter to evaluate it, but this is really only useful for one-liners.
Your magic debugging function is console.println(). Note that the JS console actually supports things like setting break points, stepping through code, and so forth. All very handy.
A good script to start might be something as trivial as:
app.alert( "hello world" );
or
console.println( this );
You'll find that this is almost always the document object.
What are you trying to do with your PDF script?
PS: There actually IS a way to communicate between a web page and a PDF, but it's a little convoluted, and I've never actually seen anyone do it. Both the page and the PDF have to use specifically named functions that are called by The Other Environment.
Other handy code snippet:
// assuming 'this' is the "doc", which as I noted earlier, is generally the case
this.getField("fieldName").value
function whatAllDoesThisThingHave(thing) {
console.println( thing );
for(var i in thing) {
console.println( "\t" + i + ": " + thing[i] );
}
}
this.submitForm(url, bazillion, other, parameters, check, the, docs);
To access the PDF control, I think your best bet would be something I found here:
Recommended way to embed PDF in HTML?
Specifically:
<div id="pdf">
<object width="400" height="500" type="application/pdf" data="/my_pdf.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0" id="pdf_content">
<p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>
</div>
I believe you can access the ActiveX control via getElementById("pdf_content"), though I could be mistaken. I'm a PDF Guy.

I seem to have found something from one of Adobe's manuals relevant to this question.
It is not a total answer, but at least it can help.
On Windows, the only OLE automation
supported for Adobe Reader is the
PDF browser controls interface, which
enables you to treat a PDF document as
an ActiveX document within an external
application. This makes it possible to
load a file, move to various pages
within the file, highlight a text
selection, and specify various print
and display options, as shown below.
If this helps to manipulate PDF from HTML JavaScript, the question is now:
how could I access PDF browser controls interface??
The manual says I should use, AxAcroPDFLib.AxAcroPDF this PDF browser controls but how should I access that??
I think all the puzzle pieces are on the table, I just don't know how to put them together!!

Related

What functionality is the java code responsible for within the GraphEditor in the mxgraph example for javascript?

I am studying the grapheditor example under mxgraph's javascript https://github.com/jgraph/mxgraph/tree/master/javascript/examples/grapheditor
However, I notice there are two parts. There's a javascript/HTML portion in the www folder. And there's a java portion.
I am a bit rusty from my Java, so I cannot be sure what the Java code is responsible for.
Does the Javascript and HTML portion be totally responsible for the UI/UX display of the GraphEditor example?
Meaning to say things like displaying the action menu and drag and drop etc are handled by the javascript and html portion?
So what's the Java code responsible for exactly?
The front-end part is only client-side JavaScript and HTML. The Java back-end is partly historic for older browsers that couldn't do things like open/save locally without echoing the file via a server.
There's also export functionality on the server. A long time ago browsers couldn't generate raster images (like PNG) locally, so the server had to do it. Now IE 11 is the only supported browser that cannot do this.
There's also PDF export, no browser can currently do this, so that's always generated on the server. See https://github.com/jgraph/mxgraph/blob/master/javascript/examples/grapheditor/java/src/com/mxgraph/examples/web/GraphEditor.java

call a js function from links in pdf

We use iframe to show pdf in our angular webapp. These pdfs have href links inside them that actually are calls to javascript function.
It looks like below.
href="javascript:openMyLink('stringOfInformation')"
function openMyLink is supposed to be present in my webapp and it will use passed stringOfInformation to make further REST calls.
The problem is I'm not able to figure out where and how do I write this function. This function may be of global space but it should also be able to access my
angular services inorder to make REST calls.
I tried writing it inside my controller and even inside a separate file but it is not getting invoked.
Please guide me on this.
Acrobat does support its own flavor of JavaScript (see the Acrobat JavaScript documentation, which is part of the Acrobat SDK, downloadable from the Adobe website).
When there is some JavaScript within the PDF, it has to be Acrobat JavaScript, and follow the according document object model.
The issue is more that in order to make use of that, your users will need a PDF viewer which is smart enough to deal with Acrobat JavaScript (and that number is quite small for Windows/macOS, and very small for iOS/Android, and it is null for the PDF viewers integrated in the web browsers.
Now, if it is a simple link, you won't even need Acrobat JavaScript. Instead of that specify the link within the PDF, using the Link tool. This may be understood by even a bit a bigger range of PDF viewers.

HTML Source-Code rip-save?

i came across a js library (jsMovie) and wanted to see the example files, but it is really badly documented (usage), so i tried to download the authors page to look in the source-code. But when trying to do that, I've recognized that "view-source" wasn't giving the full code (almost 80% of the code did not appear). (Tried in Chrome, Firefox)
So my question is, how can this be? Firebug is displaying everything propperly. At this moment i thought, that this could be as well a good way to prevent kiddies from ripping sites.
here the page: http://konsultaner.de/entwickler#Konsultaner
Hints are welcome
Generate the current source code, as interpreted by the browser. This can be done using an XMLSerializer on document.
var generatedSource = new XMLSerializer().serializeToString(document);
From there, if you want to open a page just showing the source, you could do
window.open('data:text/plain,'+encodeURIComponent(generatedSource), '_blank');
They are using AngularJS, a front-end javascript framework. That means almost all parts of the page are generated dynamically using javascript. Therefore, you can't see the page without javascript running (using view-source), but you can see the generated HTML via inspector.
If it is a static website (the javascripts and templates are all there), you can still 'rip' it. But not if it is a dynamic website, since all data and logic are 'fed' by the server.

How to insert function in PDF document?

Is anyone familiar with plugging a function into a PDF document (specifically, the "insert custom code" feature in Adobe Acrobat Pro)? I know it's possible to initiate a function on an event...but I'm not sure what event would best handle this. I'd assume a button press. Also, does anyone know which language is compatible with PDFs? Is Javascript the only one? I don't imagine a server-side code (like PHP or Ruby) would work. Or the use of a framework like JQuery. Maybe it's only ActionScript or some strict language like C#. I dunno :S
Have a look at this page on the Adobe Acrobat developer site:
http://www.adobe.com/devnet/acrobat/overview.html#JavaScript
This explains that the language you're referring to is JavaScript with a number of additional objects related to Acrobat itself exposed.
So if you want to add functionality inside a PDF file (commonly either as the result of a button press indeed, but you can also do field validation, things at document open etc...) it will have to be JavaScript. Read this page to get all details about JavaScript (including the reference):
http://www.adobe.com/devnet/acrobat/javascript.html

Inline CSS/Javascript into a HTML file

I am looking for a simple commandline script/program to automatically "inline" all external css and javascript references for a html file. I basically want to create a single self-contained html file suitable for sending via E-Mail. An additional bonus would be if it could also inline images as data: UIRs, but that part is not so important.
EDIT : I wrote a little Python script for fun. It seems to work pretty well :
Inline2Mail
Or you can still try with :
Front compiler does something like that but it implies javascript. You have an online solution as well, with premailer. Finally you have a Python and a Ruby script to do it.
There is a Node.js library which solves exactly your problem: https://github.com/remy/inliner/ It can be used both as a commandline script and a library.
It will make you a single .html file which can be sent anywhere by any means and be opened later in any browser without the need in Internet connection.
If you think about inlining CSS and Javascript to make a HTML body of an email, just forget about it. Most Email clients out there will either ignore or badly damage your styles and I think all email clients will just plainly drop the inline Javascript in the body of emails.
This Python project of mine can help with getting the CSS styles inline https://github.com/rennat/pynliner
If it's not something that needs to be automated and you're using Windows you could open the web page in Internet Explorer and save it as 'Web Archive, single file (*.mht)'. This will pack everything into a single file, including CSS, JavaScript and images. Note that the recipients needs to have access to Internet Explorer to be able to open the Web Archive. Neither Google Chrome nor Firefox supports mht files, so it's probably a Microsoft only feature.

Categories

Resources