Acrobat JavaScript: Directory Contents and Hyperlinking Files - javascript

I've recently been looking into automating a few things in Acrobat through JavaScript and had a couple questions that came up. I'm wondering if anyone might have thoughts or tips on these, it would be appreciated!
Is it possible to either get the contents of a directory (so the list of documents can be stored as an array), or check for the existence of a file? From what I've gathered, this may not be something that JavaScript in Acrobat is able to accomplish due to lack of access to the file system.
Two tricks that I've seen suggested for checking to see if a file exists are to either import it as an attachment, or attempt to open the file and see what the result is. e.g. if (this.importDataObject("myFile", "/testfile.pdf/")) { This doesn't seem to work well for my situation as the files in question can be quite large, and importing or opening them can be slow.
Is there a best way to use JavaScript to set a hyperlink in a pdf to open a file? I've tried l.setAction("app.openDoc(\"testfile.pdf\")") which adds the quoted JavaScript to the hyperlink and uses it to open the file in a new window, but I'm wondering how this compares with the way Acrobat normally links to a file, or if there's another more optimal way to set this programmatically.

For question #1 - Short answer is "No". As you said, Acrobat JavaScript doesn't have access to the file system. Long answer is "Yes - depending on what you want to do". Acrobat has a way to run "Actions" that can process all the files in a given directory, a list of files, or all the files that are currently open. You can run JavaScript on each file in a directory using an action without that script needing to actually know the file name.
For Question #2. The only option you have to set a link action via JavaScript is to set the JavaScript action. If you create a link, you only get to set the mouse up action. However, you can add a button instead of a link where the background and border are transparent and there's no caption and you get something that visually looks like a link but you can set more actions like mouse up, down, and rollover (enter/exit).

Related

Using Tampermonkey to automate download of csv file on webpage [duplicate]

This question already has answers here:
Save images to hard disk WITHOUT prompt?
(6 answers)
Closed 3 years ago.
I'm a complete newbie to this, but I'm trying to put together some code that will automatically download a .csv file from a webpage every hour and save it to my computer (preferably a specific place). The data is hourly rainfall data from Scotland at the following website.
http://apps.sepa.org.uk/rainfall
Basically I need to be able to select one of the sites in the map on the left (it'll be the same site each time) and download the hourly rainfall .csv file from the dropdown menu on the upper right hand side of the graph. When doing it manually you hover over the download button, then hover over "Download as..." then select "CSV" when it comes up.
From what I've read on here, the Chrome Tampermonkey extension used in conjunction with the Windows Task Scheduler might be the best way to do this. From the previous question there is the code:
document.getElementById("download_button").click();
I've tried to replace the "download_button" section with something that might describe the ID of the CSV button element on the page, such as using 'CSV'; but I'm really not sure what the element ID of the button is. I've tried inspecting the element in the source code but as I'm new to this I don't really know what I'm looking for.
I also tried to search for the element by class and by path but again I was really unsure as to what value for the class and path to put in to get to the specific download button I required.
document.getElementByClass("export-main").click();
document.getElementByPath("//*[#id=\"chartdiv\"]/div/div[2]/ul/li/ul/li[1]/ul/li[3]/a/span").click();
Any help would be greatly appreciated, I'm not even sure if it's possible or if this is the best way to go about it.
Thank in advance for any help you might be able to give me.
Just as a proof of concept, better approach would be to aim at specific http GET request for the data (location) that you need. That way you get JSON formatted response that you asked for (can be converted to CSV). Google how to open Chrome DevTools (F12), you will find request that you need on Network tab (bunch of requests, some of them holding data that you need in the response).
When you copy request URL (from network tab), follow instructions from this page to execute download from command line.
When prepared, you can execute that command through windows task scheduler.

How to extend tinymce's media plugin?

TinyMCE already has a bunch of nice plugins out of the box. One of them - media plugin - wich i would like to extend.
Problem: I use an exterenal Video service with an API. In order to play video on the page, i need to embed it with an iframe. The iframe-code - especialy the src-attribute - can be generated only on the server by specific page_id and video_id and some other data from database. So whoever tries to embed a video from that particular video-service needs an already generated iframe-block or at least a generated url and that is the problem.
Goal: Somehow extend tinymce' functionality. Ideally the "media" plugin.
I would like to add either a new input-field to "General" tab or create a separate tab with additional input fields. Something like that:
or
Question: What would be the best (or simplest) way to achive this ?
The best, and only, way to achieve this is to edit the code (plugin.js) of the media plugin (the non-minified files can be downloaded here https://github.com/tinymce/tinymce)
Adding a tab and fields to the interface can be done by extending the tabpanel (in the file around line 155). And furthermore writing the code to submit your fields to the editor. I have worked with plugins in tinymce before and must say it can be a complicated matter.
A very short introduction on plugins in tinymce can be found here: http://www.tinymce.com/wiki.php/Tutorials:Creating_a_plugin
Good luck!

How can I make an html file that lists files in its directory?

Here is the problem I am dealing with:
There are very few windows programs that display animated .gif images at the correct frame rate. Probably because they all use the windows libraries (probably .net) to do this, and anyone who has tried viewing an animated gif in I.E. and found that it was playing WAY TOO SLOW knows that Microsoft failed on this spectacularly.
The web browser Chrome is one of the few programs for windows that always plays animated gif's at the correct framerate, so my solution is to create a stand-alone html document to open in Chrome, that can be dropped into a directory and opened in Chrome to thereby display all images in that directory and/or its sub-directories in a picture-viewer style.
So far, my document (gif_view.html) opens an image based on a hard-coded path/file name, zooms this image in/out with the up/down keys, and switches to other hard-coded images with the left and right keys.
What I want is for these image file names to not be hard coded. gif_view.html should use a script to find out what images and sub-directories are in the directory I placed it in, and cycle back and forth through them with the arrow keys. It should also eventually create a list of sub-directories and let the viewer browse them.
Unfortunately, I can't get it to do either of these things on its own, since (for security reasons) JavaScript has no way of looking up the contents of a directory.
Does anyone know of a way to do this? Perhaps another scripting language to handle the left/right keys? Or is there a way to programmatically read the directory with JS that I missed? Or has Microsoft FINALLY released a patch or something to fix the frame-rate problem?
Please keep in mind: this should be a STAND ALONE DOCUMENT with NO external dependencies. A user should just be able to drop in into a folder, open it with a browser, and watch the magic happen. If your solution involves anything outside of the document itself (like say installing Apache and some server-side script to do the file reading) then it is not a solution. I've already tried stuff like that myself. Such external solutions work, but they are each very clumsy for their own reasons.
If anyone has ideas, I'd be grateful.
Using Chrome's directory upload feature, this is a breeze. Firstly, put a file select field in your file's HTML code:
<input type="file" id="file_input" webkitdirectory="" directory="">
and then, when the user selects a folder using it, you can read stuff like this:
document.getElementById('file_input').addEventListener('change',function(e){
var gifs=e.target.files;
[].forEach.call(gifs,function(curGif){
var elt=document.createElement('img');
elt.setAttribute('src',(webkitURL||URL).createObjectURL(curGif));
document.body.appendChild(elt);
});
},false);
this doesn't have all the fancy stuff with the arrows, but it works: http://jsfiddle.net/markasoftware/m65u7/1/

Make edits to a webpage and save the changes locally

I am wanting to find a way I can have others edit a html webpage (found locally) and allow them to save the changes they have made.
I know this is an odd request, I have a very specific idea in mind, which I will include below as an optional read for those interested.
I found that this code in the address bar works for the editing: document.body.contentEditable='true'; document.designMode='on'; void 0
Then I found that just adding:
<div id="columns" contentEditable="true">
gets the job done since I can edit the html.
The problem is that I cannot save the changes. I have tried saving the page in several different formats, including webpage/complete, HTML only, TXT file.
Is there anyway to save these edits whether by saving the HTML or using some other kind of simple storage?
Reasoning:
I have a simple local html page I will be using with other co-workers. These co-workers are not very tech-savvy (even less than me). The very mention of trying to explain how to edit the html and make changes to the text created blank stares, and an unwillingness to work on the project. I would very much prefer for them to be able to edit the text of this HTML page from the front end and not mess up any of the coding.
Also, I have installed a Xampp server, and wordpress - this has become a bit overkill for the purpose and again, has confused the others.
Thanks,
Go into JavaScript. Select and right-click on . Click copy as html. Then save into a .txt file somewhere. If you want to restore the website, right-click on and select Edit as html. Copy/paste the code in. Then it's back to normal.
You can use localStorage to save the data in the user's browser.

VBA Internet Explorer Download

First of all, I want to say that stackoverflow has helped me a GREAT deal with my current project, so thanks! But I have hit a point where I can no longer find help by skimming through previous questions. First, a little overview of what I'm doing.
At my job we have this extremely tedious process that we perform regularly, and I really want to automate it. The process is very basic, we go to a website, log-in, navigate to the appropriate page, copy and paste 6 values from excel into a form on the website, submit the form and download a specific output report. We repeat the process 60 times so this seemed like a prime candidate for Excel-Internet Explorer automation.
I built a pretty basic Excel Macro that can open up a new window with the appropriate URL, log-in, navigate to the correct page, fill in the form and submit the form, but I cannot figure out how to download the report. There is some added complexity to this, and I am just not familiar enough with Javascript, PHP ect. to figure out what is going on.
Problem: when I choose the correct report to generate, a new window pops-up with the generated report. This page is essentially empty when I click "View Source Document." There is a link to a Javascript page in the header, there is a little bit of CSS directly in the page, and like two tiny snippets of HTML. There is a download button on this page, but it doesn't look like it's being created in HTML.
QUESTION 1: Is this a Javascript application? Is there a way for me to simulate pressing the download button?
From what I understand, the complexity of my macro will increase substantially if I have to navigate between two IE windows, (not to mention there isn't an HTML link for me to click to download the spreadsheet) so I started to try and figure out a different way to do this. I looked at the URL of the new window with the generated report, and tried to analyze what was happening with Firefox's Developer tools (specifically Web Console). Here's where I get even more lost...
There are a series of "POSTS". These POSTS show up when the output is being created within the website:
POST https://www.website.com/somethingdb/quickframe/prod/#####/single_frame_results/correct_output.asp?THIS_KEY=370120c59da884dbdc375b1582a2142c1363533393a313335363032353737363a3646314a313937334a32353030303&bEmbedded=1
POST https://www.website.com/somethingdb/javascriptsource/prod/#####/website/forms/datagrid/DataGrid.html
POST https://www.website.com/qc?function=QuickFrameRmi
Then when I click the Download button, One POST and one GET show up:
POST https://www.website.com/qc?function=CorrectReport.generateExportFile
GET
GET https://www.website.com/somethingdb/quickframe/prod/#####/dlf/x6::370120c59da884dbdc375b1582a2142c1363533393a313335363032353737363a3646314a313937334a323530303031356026339.xls/sfn/RIGHTPAGE_scen_1_deal_cf.xls
The referrer for the GET looks like this:
https://www.website.com/somethingdb/quickframe/prod/#####/single_frame_results/correct_output.asp?THIS_KEY=370120c59da884dbdc375b1582a2142c1363533393a313335363032353737363a3646314a313937334a32353030303&sPagename=RIGHTPAGE&nScenarios=1&bShowExtendedFields=1&bShowAllCollats=0&ShowUnderlyingPage=0&sUnderlyingPage=&WebsitewrapDb=websitewrap&iSettleId=&bScrollbars=true&time=1356025839577
Like I said, my knowledge of these things is very limited but I do know that once I click on the download button, the GET from above is an actual file name that is stored on the website’s server. I can go into Excel, click on “Open” and put that file path in and it will download EXACTLY what I need.
So here is what I am thinking. If I could tell the website to simulate the download process, and log what that GET is, then I could just store that away, and when the Macro finishes generating all of the reports I need, it can just navigate back into Excel and set up a simple Loop to download all of them?? I have identified the portions of the GET that change:
x6::370120c59da884dbdc375b1582a2142c
63032353737363a3646314
6026339
This is my first post, so I apologize if I was too long winded in my back-story. Just wanted to be as clear as possible from the get go. I am wondering what is truly happening inside the website? Is what I am suggesting making sense? Is it possible? Is there a better way. Thanks in advance for any help.

Categories