How to read form fields of indd file - adobe-indesign

I have made a .indd file with some form fields in it.
Now I want to get all these fields through indesign script and manipulate its content
so that i can change the content of fields and apply these changes to .indd file.

Well I have got this and able to get all fields of the doc.
var myDoc = app.open(File("fileName.indd"));
var allformFields = myDoc.formFields;
for(var i = 0; i < allformFields.length; i++){
var tf = allformFields[i];
alert(tf.name);
}

Related

GoogleSheet: Insert Image Based on Cell Value and File Name

I am looking for a GoogleScript which can automatically insert the image in the cell based on File Name. The steps are below:
Get Name (in Column A)
Lookup the image file in "Image Folder"
Insert the image with fixed size (Column B)
I am attaching the sheet for your understanding.
GDoc
Folder
Script that I use but is not working:
function listFilesInFolder(folderName) {
//writes the headers for the spreadsheet
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Image"]);
var folderId = "1AV5pTs3l7GGMNH7-C8rixjcWNNTsmbpE";
var folder = DriveApp.getFolderById(folderId);
var contents = folder.getFiles();
var cnt = 0;
var file;
while (contents.hasNext()) {
var file = contents.next();
cnt++;
Logger.log(file);
Logger.log(cnt);
// writes the various chunks to the spreadsheet- just delete anything you don't want
data = [
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
"=image(\"https://docs.google.com/uc?export=download&id=" + file.getId() +"\")",
];
sheet.appendRow(data);
};
};

For loop over a Google Sheets Range fails to change file owner

I need to transfer ownership of thousands of files I own to someone else with editing access, but I've learned that Google Drive requires you to do this one file at a time. With intermediate but growing JS experience I decided to write a script to change the owner from a list of file IDs in a spreadsheet, however I've run into trouble and I have no idea why. The debugger just runs through the script and everything looks sound for me. I'd greatly appreciate any help.
function changeOwner() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/********/').getSheetByName('Sheet1');
var range = ss.getRange(1,1,2211);
for (i = 0; i < range.length; i++){
var file = range[i][0].getValue();
var fileid = DriveApp.getFileById(file);
fileid.setOwner('******#gmail.com');
}
}
Tested below code working fine with IDs,
function myFunction() {
var spreadsheet = SpreadsheetApp.openById('ID');
var range = spreadsheet.getDataRange().getValues();
for (i = 0; i < range.length; i++){
var file = range[i][0].toString();
var fileid = DriveApp.getFileById(file);
fileid.setOwner('***#gmail.com');
}
}
Your issue is that the Range class had no length property. Instead, perform a getValues() call on the range to efficiently create a JavaScript array, and iterate on it:
function changeOwner() {
var ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/********/').getSheetByName('Sheet1');
var values = ss.getRange(1, 1, 2211).getValues();
for (i = 0; i < values.length; ++i){
var fileid = value[i][0];
var file = DriveApp.getFileById(fileid);
file.setOwner('******#gmail.com');
}
}
There are other improvements you can make, such as:
dynamic range read (rather than the fixed assumption of 2211 rows of data)
writing to a second array to keep track of which files you have yet to process
checks for if the file exists
checks for if the file is actually owned by you
checks for execution time remaining, to allow serializing any updates/tracking you do that prevents the next execution from repeating what you just did
and so on. I'll let you research those topics, and the methods available in Apps Script documentation for the DriveApp, SpreadsheetApp, Sheet, and Range classes. Note that you also have all features of Javascript 1.6 available, so many of the things you find on a Javascript Developer Reference (like MDN) are also available to you.

Indesign server data merge

I am trying to do a data merge using Indesign Server. test.indd in the script below already has all the merge fields assigned. I only need this script to open the file, do the merge, and save the merged file. The file that gets saved is the original test.indd file, and not the merged file. I'm not sure how to access the merged file.
var myDocument = app.open(File("/C/inetpub/wwwroot/datamerge/test.indd"));
with (app.dataMergeOptions) {
linkImages = true;
removeBlankLines = false;
createNewDocument = true;
documentSize = 100;
} // (end of dataMergeOptions)
myDocument.dataMergeProperties.mergeRecords();
myDocument.save(new File("/C/inetpub/wwwroot/datamerge/mergedOutput.indd"));
myDocument.close ();
If someone can have a look and let me know what I'm missing. Or direct me in the direction I should be going.
Your dataMergeOptions tell the application to create a new document but you are saving the document in your myDocument variable which is your template. You need to either get a hold of the newly created document and save that or remove the createNewDocument option.

Parse PDF with ABCPDF

I want to parse a PDF document I download with ABCPDF, but I cant find any elements in the document or how to reach them and iterate them. I want to parse out some text.
var webClient = new WebClient();
var bytes = webClient.DownloadData("http://test.com/test.pdf");
var doc = new Doc();
doc.Read(bytes);
Use the Doc.GetText method to extract content from the current page, specifying the format in which content is to be returned.
doc.PageNumber = 1;
string pageContent = doc.GetText("Text");
The example above will return plain text in layout order. Specifying "SVG" or "SVG+" returns additional information along with the text, such as style and position.

google spreadsheet api for arabic

I am trying to read a spreadsheet using google spreadsheet api.
Everything went well, but when I put russian or arabic texts in the spreadsheet
my program prints ?????? ?? ????? values for those cell values.
below is the code to read spreadsheet from my google account.
SpreadsheetService service = new SpreadsheetService("MyApp");
service.setUserCredentials(USERNAME, PASSWORD);
URL feedUri = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full?title-exact=true&title=internationalization_contents");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(feedUri, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
SpreadsheetEntry spreadsheet = spreadsheets.get(0);
// get the first work sheet
WorksheetEntry workSheet = spreadsheet.getWorksheets().get(0);
URL cellFeedUrl = workSheet.getCellFeedUrl();
CellFeed cellFeed = service.getFeed(cellFeedUrl, CellFeed.class);
List<CellEntry> entries = cellFeed.getEntries();
for (int n = 0; n < entries.size(); n++) {
Cell cell = entries.get(n).getCell();
System.out.println(cell.getValue());
}
this prints something like
title
welcome
???? ?? ????
anybody knows how to get characters properly to my java application.

Resources