I am trying to use Adobe Javascript to change the properties of a fillable form text box when a signature is added to a signature block.
A PDF file is created by exporting from Excel into PDF.
An Action is then used to Detect Form Fields which produces 2 text boxes and 2 signature blocks automatically.
The Action then runs this:
var f =this.getField("Signature").required = true ;
to make the first signature block a required form.
Everything is successful up to this point.
The action then attempts to run this:
var f =this.getField("Signature");
var oLock = f.getLock();
oLock.action = "include";
oLock.fields = new Array("Receivers CommentsRow1");
f.setLock(oLock);
Which throws up the error
TypeError: oLock is null
4:Batch:Exec
Running directly from the console gives the same error.
Any help is appreciated, thanks.
According to the documentation http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/Acro12_MasterBook/JS_API_AcroJS/Field_methods.htm?rhtocid=_6_1_8_31_2_12#TOC_getLockbc-13
oLock.action = "include";
"include" should be initial caps "Include".
Related
I'm trying to re-purpose some older java script code that I use in order to create a text file via an intranet web app. The following code creates text files that are picked up and processed by a third party application running on the same device...
<script>
function WriteTransferFile(location) {
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
var fileObject = fileSystemObject.CreateTextFile("C:\\transfer\\transfer.txt", true);
fileObject.Write(location);
fileObject.Close();
return location;
}
</script>
<script id="writetransfer">
function writetransfer() {
var Location = document.getElementById('lblCommand');
var Command = Location.innerHTML;
WriteTransferFile(Command);
}
</script>
This works fine for a single text string to be pasted into a text file, but I now need to create a file which takes 4 different fields from the web page and writes them on to consecutive lines. I've played around with the above but any attempt to add a second line of text overwrites the first line instead creating a new one below it. Desired output...
Field 1
Field 2
Field 3
Field 4
Any ideas how I might accomplish this?
I'm aware this probably isn't the sleekest solution, but there are no concerns regarding the suppression of active X security settings as this is for a closed system with access to local intranet only.
Thanks
Steve
I have Javascript code that attempts to paste an image file, which has been copied from the Windows clipboard.
This code works perfectly well in Chrome and Edge but not in Firefox.
It will only work in Firefox, if the image is copied from an image-editing program, e.g. Paint.
A fragment of the event handler is similar to this:
var items = (e.clipboardData || e.originalEvent.clipboardData).items;
When executed using Firefox, the files collection in e.clipboardData is empty, as is the items collection.
I am aware that this is a duplicate question, that was asked 3 years ago:
Javascript clipboardData.items and clipboardData.files are empty when pasting an image
I'm asking it again in the hope that someone knows of a work-around to this issue, or at least, an admission from Firefox that they do not support this functionality.
I found eclipboardData.items not to be helpful and needed to use file_input.files = e.clipboardData.files.
I'm having additional issue in Firefox, specifically when using a form and script that are dynamically added to the page and shown in a modal (no iframes). I found that the File object is available DURING the paste event, but is no longer available after.
I tried using FileReader and creating a new File, but ended up with the same result. I used a (bad) workaround that auto-submits the form during the paste event, which won't be sufficient for all cases.
I have no issues with the File object later disappearing if the form & script load in the initial page request, but I want to include this just in case you're having the 'disappears after paste event' issue.
Example:
//setup the paste listener
document.body.addEventListener('paste',
async function (e){
const form = document.querySelector('form[action="/files/upload/"]');
const file_input = form.querySelector('input[type="file"]');
// display error if no files to paste
const err = form.querySelector('.file_input_error');
if (e.clipboardData.files.length == 0){
err.innerText = 'No images in the clipboard. Copy an image and try again.';
err.style.display = "block";
return;
}
file_input.files = e.clipboardData.files;
// show_file(file_input); // custom function to display the image in the form
// fire the change event
const changeEvent = new Event("change");
file_input.dispatchEvent(changeEvent);
}
);
//use a file_input change event to submit the form, so it works for both copy+paste & regularly adding the file
file_input.addEventListener('change',
function (e){
const form = document.querySelector('form[action="/files/upload/"]');
form.querySelector('input[type="submit"]').click();
}
);
I use selenium to get reports. I wrote the following code to check if the report was received.
# switch to new tab
driver.switch_to.window(driver.window_handles[-1])
# navigate to chrome downloads
driver.get('chrome://downloads')
# define the endTime
endTime = time.time()+20
downloadPercentage = driver.execute_script(
"return document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('#progress').value")
print(downloadPercentage)
But on the last line I get the following error
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'value' of null
'#progress' is not an input field to get its value with querySelector('#progress').value you need to modify it to querySelector('#progress').getAttribute('value').
so, modify
downloadPercentage = driver.execute_script(
"return document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('#progress').value")
to
e = driver.find_element_by_id('progress')
downloadPercentage = e.get_attribute("value")
(Updated on 2021-02-01, based on comment)
I use another solution.
As soon as download started I switch to edge://download (chrome://download) page and start parsing it regularly (i.e. once in 3 seconds) waiting till "Cancel" or "Pause" title disappears.
When these words disappear (in fact converts to "Show in folder") it means the file has been downloaded.
I have an XForm document in LibreOffice Writer 5. The form contains various text boxes and date fields. What I want is to create a Javascript macro that will be assigned to one text box and perform some actions whenever the user changes the input of this field. So far I have written the following
var oDoc = UnoRuntime.queryInterface(XModel, XSCRIPTCONTEXT.getInvocationContext());
if (!oDoc) {
oDoc = XSCRIPTCONTEXT.getDocument();
}
var xFieldsSupplier = UnoRuntime.queryInterface(XFormsSupplier, oDoc);
var xForm = xFieldsSupplier.getXForms();
but xForm is null. Does anyone know how I can get the XForm fields? Is there something wrong with the above code?
The code looks fine. It seems to be an issue with Javascript, because I tested similar code using other languages and it worked. In Python this printed the form name:
xforms = oDoc.getXForms()
formName = xforms.getElementNames()[0]
xTextRange = xText.getEnd()
xTextRange.setString(formName)
xform = xforms.getByName(formName)
The same thing worked in Java:
XFormsSupplier xFormsSupplier = UnoRuntime.queryInterface(
XFormsSupplier.class, xComponent);
XNameContainer xforms = xFormsSupplier.getXForms();
String formName = xforms.getElementNames()[0];
xTextRange = xText.getEnd();
xTextRange.setString(formName);
Object aForm = xforms.getByName(formName);
This introduction indicates that Javascript support for UNO is still in its infancy.
Note that XFormsSupplier is not published, which presumably means the interface is subject to change or instability.
I am in big problem. I have to update person information from a csv file. But I also need to save status when the person Id was searched. It can be already updated, incorrect or may open a per populated form.
I need to extract that dialog text and save in a status.csv file. If no error occured then I can update the form and submit it, and again the text in the last dialog can be extracted and saved in a status.csv file.
Is there any solution for extracting dialog text with iMacro and js on Firefox. The solution link given on the iMacro wiki didn't work for me.
This question is not useful: not a solution for firefox
Perhaps this solution would work for you:
// imitation of javascript dialog
var ret = iimPlayCode('URL GOTO=javascript:{alert("Dialog<SP>text<SP>to<SP>be<SP>extracted");}')
// extracting dialog text
if (ret < 0)
var dlgText = iimGetErrorText();
dlgText = dlgText.match(/Dialog message: "(.*)",/)[1];