My goal is to have the user press a button to select a file ONE TIME that will be used both as an attachement and the button icon. I know how to do each of these tasks separately, but this requires my user to select the same file twice. I am looking for a way to either:
Have them import a file as a button Icon, then change the Icon into a DataObject and attach it to the pdf
Have them import a file as a DataObject attachment, then convert it to an Icon
Is this possible? I haven't been able to figure this conversion step out.
Thanks
You can prompt the user for the file to import once and then use the path for the two use cases you need.
var img = app.browseForDoc(); // prompts the user to select the file
var imgPath = img.cPath; // get the device independent path to the file
this.importDataObject("myDataObjectFileName", imgPath); // import the data object
this.getField("myImageButton").buttonImportIcon(imgPath); // set "normal" the button face
Your button must be set up to show an icon first and you'll also want to set the scaling properties as well. You can make the attachment name the same as the file name with some simple string functions on the path.
Related
I am using a tool called TamperMonkey to modify a webpage for my personal convenience. TamperMonkey lets you modify the client-side HTML etc. by appending JavaScript to the page after it loads.
The webpage has a file chooser, but it doesn't let you drag-and-drop a file. I use this webpage a lot so having drag-and-drop functionality would really help.
This page has a form with a file input type. I've been reading, and there's no way to modify a file input type for security reasons. But, using TamperMonkey, I could change the input type of the file chooser to "hidden," then set the hidden input value to the file contents that I drop on the webpage, right? It's my understanding that the server couldn't tell the difference (if the name attribute is the same).
I don't know how to set the hidden input type to the same data the file chooser would have:
I've got my file here: const file = e.originalEvent.dataTransfer.files[0];
I've got my hidden input type by doing this: const hiddenField = $("iframe").contents().find(".file-input").attr('type','hidden')
I just don't know how to take file and set it on hiddenField. Should this value be base64 encoded? A blob? Regardless, what code would set the data correctly?
The form it's wrapped in looks like this:
<form ... method="post" enctype="multipart/form-data">
Important context for alternative suggestions: this file chooser input isn't on the page at all until you click a button. Then it shows up in an iframe.
I am using firefox.
It is possible to modify a file input type with Tampermonkey.
If you are not able to add drag and drop support to the input itself straight away, you can implement drag and drop using another dom element and use them as below.
const dT = new ClipboardEvent('').clipboardData || // Firefox < 62 workaround exploiting https://bugzilla.mozilla.org/show_bug.cgi?id=1422655
new DataTransfer(); // specs compliant (as of March 2018 only Chrome)
dT.items.add(new File([dataURItoBlob(image)], '1.jpg', { type: 'image/jpeg' }));
dT.items.add(new File([dataURItoBlob(image2)], '2.jpg', { type: 'image/jpeg' }));
// then ...
// $("iframe").contents().find(".file-input").get(0).files = dT.files;
That snippet of code was tested working, in a similar setting where a file input was being attached to the page dynamically after clicking a button. The images were drag n dropped onto the page using a different div.
I have a MVC project with a view. Have a directory on server with files, and have to show good looking Open File dialog box with this directory and files in it (not a user's local directory). I got a list of files, and path, and send as variables (string and array of strings) into my view, so now I can show directory listing on my page. But I'd like to use some standard looking dialog box for choosing file instead of writing my own window with radio buttons and text boxes.
Is there any way to fill Open file dialog box with my list of files With Javascript?
Regarding the buttons, you can take a look at bootstrap: https://getbootstrap.com/docs/4.0/components/list-group/
There you can use predefined buttons, lists etc. But specifically for downloading files there is no SPECIAL button of any kind.
Regarding the JS part, you can use something like:
<a id="download_link" download=filename.txt" href=”” onclick="getFile('someinputtxt')"><font size="5">Download Txt File</font></a>
<script>
function getFile(input)
{
var text = input;
var data = new Blob([text], {type: 'text/plain'});
var url = window.URL.createObjectURL(data);
document.getElementById('download_link').href = url;
}
</script>
There I create a text file with some input. But basically you can use a button/list that is already in bootstrap for example and just add the file using 'download':
Hope it helps.
I am working on my own version of a magic mirror and I want to have an icon that displays the weather based on the JSON data that it requested. It checks the weather every hour, and I want it to display one of the 4 icons (the icons are just png’s I photoshopped)
I have tried document.getElementById(“image”).appenedChild(img), but every time it requests data, it adds another icon next to the original. I can get the data and parse it, I just am new to creating dynamic webpages
Right now I have a function that checks the weather from OpenWeatherMap, then calls another function that sets the img.src to the correct icon file, but nothing shows up
The end goal is to either have the original icon updated or replaced when it receives new data
It's easier to access the image if you give it an id.
<img id="weatherIcon" src="firstIcon.png" alt="Weather icon">
Then you can change the image's src attribute to load a different image to the element.
document.getElementById("weatherIcon").src = "secondIcon.png";
I'm looking fora functionality that if you press a button or a link inside of a website, it will automatically open excel in you local computer. The button or link that you press is defined with specific data for instance data "test" and you want to have the data inside of the excel after you have pressed the button or link
Please remember that you have the data in the webpage and then when you press on the button or link you open the excel document and the data from the wepage will be transer automatically to the excel document.
Is it possible to do it? if yes, how?
I have tried finding a solution by using sourcecode but I failed.
You can use the ms-excel scheme to open a file in Excel.
A simple example:
<a href="ms-excel:ofe|u|http://berkeleycollege.edu/browser_check/samples/excel.xls">
Open in Excel
</a>
Demo: http://jsfiddle.net/DerekL/mp0p1gcq/
Another demo: http://jsfiddle.net/DerekL/x9npn97z/
Full Syntax Definition for the ms-excel scheme:
Excel Scheme = "ms-excel:" open-for-edit-cmd | open-for-view-cmd | new-from-template-cmd
open-for-edit-cmd = "ofe|u|" document-uri
open-for-view-cmd = "ofv|u|" document-uri
new-from-template-cmd = "nft|u|" template-uri ["|s|" save-location]
document-uri = URI location of document to open
template-uri = URI location of template file upon which new file will be based
save-location* = URI location of folder in which new document should be created
*save-location is an optional parameter
Below code is working fine to write XML data into a file.
function btnSave_onclick() {
var aFSO = new ActiveXObject("Scripting.FileSystemObject");
aTS = aFSO.OpenTextFile(FilePath,2,true);
aTS.Write (XMLText.value);
aTS.Close();
}
I want to change this code to show a dialog box to saveAs in desired location.
I found below code to open save as dialog box
document.execCommand('SaveAs','true',filename.txt);
Now question is how can I save data (which is in XMLText.value) through This dialog.
Is there any other way to save data trogh dialogBox. It is for IE
In other way Is it possible to provide a Browse button to select desired location in c: drive or any other drive and by saying ok get that path and store in a variable and by using above code can save directly to that location.
But here question is how to provide browse button?