Using Acrobat javascript to write a text file - javascript

I am using acrobat XI to write some script. What I would like to do is 1) get the current processed pdf file name and 2) just simply output a text file
var textValue = "test";
var doc = this.createDataObject({cName: "test.txt", cValue: textValue});
this.exportDataObject({cName: "test.txt", nLaunch:0});
This is working , but I would like to provided a fixed path , I tried saveAs but it seems only for pdf , exportAsText not working as well.
Are there any way to fix it? thanks

Official documentation says:
Example: Save the current document in rich text format:
this.saveAs("/c/myDocs/myDoc.rtf", "com.adobe.acrobat.rtf");
I guess you can replace RTF format with TXT (com.adobe.acrobat.plain-text):
this.saveAs("test.txt", "com.adobe.acrobat.plain-text"); // try this

Related

javascript to change text contents in JS file

i have an .js file in which Text contents have to replaced with the text content in excel
for example
var gCategory_CircuitDiagram = "Circuit Diagram";
var gCategory_HarnessLayout = "Harness Layout";
var gCategory_PowerSource_Grounding_SneakPath1 = "Power Source";
var gCategory_PowerSource_Grounding_SneakPath2 = "Power Source / Grounding / Sneak Path";
var gCategory_Connector = "Connector";
var gCategory_Junction = "Connection information";
in this textcontents("Circuit Diagram") inside the double quotes i have to replace with contents in excel can anybody tell me how to get JS file and xml data as input replace all the text contents , i will be very thankful to you if you help me in this case.
with regards,
karthik
I'm not sure to understand what process you're trying to develop here exactly.
From what I get you could write a script using nodeJS and 2 module, xlsx and xml2js.
The xlsx module would allow you to read your excel file and get a Object from it.
You can then edit this object with your list of changes ('circuit diagram', etc.).
When it's done you can generate an xml file with the xml2js module
https://www.npmjs.com/package/xlsx
https://www.npmjs.com/package/xml2js

document.write and JSON output

I have some big json configs and want allow users to export them. The problem is JS prompt cant return a full data, so i decided to use windows.open and write. But "write" just "eat" html in json values. This answer https://stackoverflow.com/a/22055706 helped a lot.
var data = Store.export();
var url = 'data:text/json;charset=utf8,' + encodeURIComponent(data);
window.open(url, '_blank');
window.focus();
But when i try to export really large and long json everything freezes...
How can i modify it to use blank url and unmodified json as text?
UPD
My workaround
var myWindow = window.open("", "JSON Settings", '_blank');
myWindow.document.write('<textarea>' + escapeHTML(Store.export()) + '</textarea>');
myWindow.focus();
You could include a multi-line text field in which you would place the data.
This gives it a space to go rather than just being injected into the HTML.
The user would then copy and paste the data out into their own .json file.
If you're trying to export the data, do you have any requirements prohibiting the user from downloading the data?
This lib has come in handy for me several times:
https://github.com/eligrey/FileSaver.js

JavaScript to .csv download fails: "Failed. No File"

Right now I'm just trying to get anything to work. My browser is Chrome 40.022. When I click my download link, it initiates downloading but then fails with the error Failed. No file. What am I doing wrong? Is this a browser thing?
Javascript:
var fileName = "data.csv";
var csv = "abc, def, hij";
//I'm partially using angular in this page...
$scope.link3 = 'data:text/csv;base64,' + btoa( csv ); //forgive the variable name
HTML:
<a ng-href="aap.link3" download="data.csv">Hello</a>
I created a jsfiddle for your problem. There are 2 issues with your code:
In your case, ng-href data need to be interpolated
You must add data into whitelist for Href attrtibute, else it will
be transformed into 'unsafe'.
https://jsfiddle.net/8o1v1uym/

HTML Desktop Application, Read/Write File From HTML/JS

I have create an HTML application located on my computer, I use it with Firefox.
I need that this Html page reads and write on a simple txt file on my computer.
Preferably using only html/JS
Here's a definite solution
var txtFile = "c:/test.txt";
var file = new File(txtFile);
var str = "My string of text";
file.open("w"); // open file with write access
file.writeln("First line of text");
file.writeln("Second line of text " + str);
file.write(str);
file.close();
You may want to check out this documentation:
http://www.roseindia.net/javascript/javascriptexamples/javascript-write-to-text-file.shtml
That should help you get started.

Problem formating Html string in Javascript to send mail

I am trying to send an email (using Outlook mail) from a jsp page.
Requirement is, when the user clicks on send email button the data stored in a string
(with HTML tags) should be passed to the mailbody.
But the problem is, the text displayed in mail body is not formatted as HTML text.
Could you please suggest how to format it as HTML text in Outlook Doc.
I have used the below code in a function-
function OpenOutlookDoc(whatform,msgBody)
{
outlookApp = new ActiveXObject("Outlook.Application");
nameSpace = outlookApp.getNameSpace("MAPI");
mailFolder = nameSpace.getDefaultFolder(6);
mailItem = mailFolder.Items.add(whatform);
mailItem.Display(0);
mailItem.To = "abc#xyz.com";
mailItem.Subject = "TEST MAIL";
mailItem.Messageclass = whatform;
mailItem.Body = msgBody; //the text here is concatenated with HTML tags
mailItem.Send();
}
Thanks for you upcoming help..
After some google'ing:
The MSDN should help:
http://msdn.microsoft.com/en-us/library/aa171418%28v=office.11%29.aspx
The article includes an example to send html emails using vb-script. Converting that to javascript should not be hard - but since activex only works from within Internet Explorer you might as well use vbscript.
Try adding message.IsBodyHtml = true; to your code.
otherwise u can refer this example.

Categories

Resources