I'm trying to add multiple annotations in pdf document through Acrobat javascript. However, only the first annotation is working if I include both. The second annotation only works if I include that one separately.
var spans = new Array();
spans[0] = new Object();
spans[0].text = "Links to: ";
spans[0].textSize = 12;
spans[0].textColor = color.red;
spans[1] = new Object();
spans[1].text = "http://www.example.com";
spans[1].textSize = 12;
spans[1].textColor = color.black;
// Now create the annot with spans as it's richContents
var annot = this.addAnnot({
page: 0,
type: "FreeText",
rect: [50, 50, 300, 100],
richContents: spans
});
var copy_annot = this.addAnnot({type: "Line"})
annot.setProps({
page: 0,
points: [[400,490],[430,690]],
strokeColor: color.red,
arrowBegin: "Diamond",
arrowEnd: "OpenArrow"
});
I had forgotten to change the variable name before setting the property
Solution:
var copy_annot = this.addAnnot({type: "Line"})
copy_annot.setProps({
...
});
Related
I have some xml or excel I want to loop through this document in InDesign script and insert values on defined places
this is excel or xml
this I want to get
I don't have so much scripting experiences so I can only this piece of code
var doc = app.activeDocument;
var myFile = File("~/Desktop/test.xml");
var textExcel = doc.textFrames.add();
textExcel.geometricBounds = [50, 80, 10, 150];
textExcel.place(myFile);
but now how I can get a single value? for example in indesign template first paragraph should look like table --> lorem--> 150
Here is the possible solution:
var doc = app.activeDocument;
// get a text from the XLSX file
var inputFile = File("d:/table.xlsx");
var temp_frame = doc.textFrames.add();
temp_frame.place(inputFile);
var text = temp_frame.parentStory.contents;
temp_frame.remove();
// make a table from the text
var rows = text.split('\r');
var table = [];
for (var i = 1; i < rows.length; i++) table.push(rows[i].split('\t'));
// loop through the table and make the cards
for (var i = 0; i < table.length; i++) {
var title = table[i][0];
var description = table[i][1];
var price = table[i][2];
var card = make_card(title, description, price);
// move the card to some places
card.move([10,10]);
card.move(undefined, [i*75, 0]);
}
// the function to create and return a card
function make_card(title, description, price) {
var doc = app.activeDocument;
var title_frame = doc.textFrames.add();
title_frame.geometricBounds = [20, 80, 30, 150];
title_frame.contents = title;
var description_frame = doc.textFrames.add();
description_frame.geometricBounds = [30, 80, 80, 150];
description_frame.contents = description;
var price_frame = doc.textFrames.add();
price_frame.geometricBounds = [80, 80, 100, 150];
price_frame.contents = price;
// apply styles to the texts in the card
apply_style('title', title_frame);
apply_style('description', description_frame);
apply_style('price', price_frame);
var group = doc.groups.add([title_frame, description_frame, price_frame]);
return group;
}
function apply_style(style_name, frame) {
var doc = app.activeDocument;
try {
var style = doc.paragraphStyles.itemByName(style_name);
frame.paragraphs.everyItem().appliedParagraphStyle = style;
} catch(e) {}
}
This is the XLSX table:
Here is the result layout (3 cards):
It creates cards from XLSX file (applies the styles to the texts inside cards, why not?) and put them on the page of the current document.
You can probably do this with xpath and Document.
https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate
You create a new Document with the xml and you evaluate a xPath.
I need to download Carbon monoxide concentrations daily data provided by sentinel 5p but the data consists of gaps for my region of interest
var dataset1 = ee.ImageCollection("COPERNICUS/S5P/NRTI/L3_CO")
.filterDate('2021-03-01', '2021-03-31')
.filterBounds(roi)
.select("CO_column_number_density")
print (dataset1)
var img = dataset1.filterMetadata('TIME_REFERENCE_DAYS_SINCE_1950', 'equals',25992 )
.mean();
Map.addLayer(img)
Google Earth Engine
This is the code used. I am trying to average the data available for a single day but there are gaps. if the data has to be averaged over more than one day, how to do it? how to create a loop that iterates over the dates and computes the average?
Try This Code
var batch = require('users/fitoprincipe/geetools:batch')
print("batch.help", batch.help)
var Sentinel_CO_Dataset = ee.ImageCollection("COPERNICUS/S5P/NRTI/L3_CO")
.filterDate('2021-03-01', '2021-03-10')
.filterBounds(roi)
.select("CO_column_number_density")
print (Sentinel_CO_Dataset)
var count = Sentinel_CO_Dataset.size()
print("Collection count", count)
var all_Sentinel_CO_tiles = Sentinel_CO_Dataset.map(function(image) { return image.clip(roi).reproject('EPSG:4326', null, 1113.2); });
var check = ee.Image(all_Sentinel_CO_tiles.first());
var Sentinel_CO_Palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];
Map.addLayer(check, {min:0.02, max: 0.05, palette: Sentinel_CO_Palette}, 'Sentinel_CO_Palette_Check');
var colList = all_Sentinel_CO_tiles.toList(all_Sentinel_CO_tiles.size());
var n = colList.size().getInfo();
for (var i = 0; i < n; i++) {
var img = ee.Image(colList.get(i));
var id = img.id().getInfo();
var listOfImages = all_Sentinel_CO_tiles.toList(all_Sentinel_CO_tiles.size());
var Tile = listOfImages.get(i);
var allRasters = ee.ImageCollection.fromImages([Tile]);
batch.Download.ImageCollection.toDrive(allRasters, "Sentinel_CO",
{name: 'MONOXIDE_'+id,
scale: 1113.2,
region: roi
})
}
I would like to add inline bold style inside the contents. How, can I achieve that? The below code output bold tag markup instead of applying the bold formatting.
var annot = this.addAnnot({
page: 0,
type: "FreeText",
rect: [50, 50, 300, 100], // location and size of text field in points
contents: "<b>Links to</b>: http://www.example.com",
});
The text field properties needs to be set to allow rich text formatting. Then you need to create an array of Span objects that contain the text with the formatting you want.
var spans = new Array();
spans[0] = new Object();
spans[0].text = "Attention:\r";
spans[0].textStyle = "bold";
spans[0].textSize = 18;
spans[1] = new Object();
spans[1].text = "Adobe Acrobat DC\r";
spans[1].textColor = color.red;
spans[1].textSize = 20;
spans[1].alignment = "center";
spans[2] = new Object();
spans[2].text = "will soon be here!";
spans[2].textColor = color.green;
spans[2].fontStyle = "italic";
spans[2].underline = true;
spans[2].alignment = "right";
// Now create the annot with spans as it's richContents
var annot = this.addAnnot({
page: 0,
type: "FreeText",
rect: [50, 50, 300, 100],
richContents: spans
});
I'm creating buttons and label from arrays via loop. I assign layer.id and layer.name to the buttons and labels. What I would like to do when button is pressed, is to draw text, describing the button color, on the appropriate line. The problem is when the button is clicked, the appropriate label is positioned , but only to the last label position and when another button is clicked the caption is written over the last caption. I want to find/assign the appropriate label using l.find("." + v2) I'm using the same function for other parts of the script and the binding works.
var s = new Kinetic.Stage({container: 'toolpanel', width:500, height:700});
var l = new Kinetic.Layer();
var cp3 = new Kinetic.Rect({x: 100,y: 10,width: 400,height:700, stroke:'black', draggable:true});
var db = [];
db.push("red_Glove Type:");
db.push("blue_Glove Type:");
db.push("black_Throws:");
var lx = 50;
for (var i = 0;i < db.length;i++){ var ser = db[i]; var sdb = ser.split("_"); v1 = sdb[0]; v2 = sdb[1];
var box = new Kinetic.Rect({x: lx+=20 , y:5, fill: v1, id: v2, name:v2, height: 30, width:30});
l.add(box); lx+=30; l.draw();
var posY = box.getPosition().y;
box.on('mousedown', (function(v1,v2){ return function(){
var check = l.find("." + "v2");
var caption = new Kinetic.Text({
x: 230,
y:posY ,
fontSize: 16,
text: v1,
id:v2,
draggable: true,
fill:v1
});
caption.setText(v1);
l.add(caption); l.draw();
}})(v1,v2),false);
}
var desc = new Kinetic.Text({x: cp3.getWidth()/ 2,y: 20,text: 'Your Personalization',fontSize: 16,fontFamily: 'arial',fill: 'black',padding: 4});
l.add(desc);
s.add(l);
var odesc = [];
odesc.push("Glove Type:_20");
odesc.push("Glove Series:_40");
odesc.push("Glove Positons:_60");
odesc.push("Throws:_80");
odesc.push("Glove Back Style:_100");
odesc.push("Hand Size:_120");
var ly = 20;
for (var s = 0; s < odesc.length; s++){
var db = odesc[s];
var sdb = db.split("_");
var text = sdb[0];
var label = new Kinetic.Text({
x: 100,
y: ly+=50,
text: text,
fontSize: 16 ,
id: text,
fontFamily: 'arial',
fill: 'black',
padding: 1,
align: 'left'
);
l.add(label); ly += 10;
var posY = label.getPosition().y;
} l.draw();
Please checkout shortened scriptjsfiddle
I'm using this code to draw a point on a map:
function addPointToMap(pMap){
var coordinates = new Array();
// Style Point
var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style_blue.strokeColor = "blue";
style_blue.fillColor = "blue";
// Make Point
coordinates.push(new OpenLayers.Geometry.Point(33, 33));
var pointFeature = new OpenLayers.Feature.Vector(coordinates, null, style_blue);
// Layer
var pointsLayer = new OpenLayers.Layer.Vector("Points Layer");
pointsLayer.addFeatures([pointFeature]);
pMap.addLayer(pointsLayer);
}
I'm getting this error from the console:
Uncaught TypeError: Object POINT(33, 33) has no method 'getBounds'
What am I doing wrong?
For the sake of completeness, I received a similar error while adding a polygon (not a point) from raw WKT data. The error that there are no bounds occur because the object was of the wrong type.
When you call addFeatures, it expects an array of OpenLayers.Feature.Vector objects, which are created by Format.read.
var wkt_parser = new OpenLayers.Format.WKT();
var wkt_data_parsed = wkt_parser.read(some_raw_wkt_data_string);
layer.addFeatures([wkt_data_parsed]);
The answer is to add a multipoint geometry:
function addPointToMap(pMap){
var coordinates = new Array();
// Style Point
var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style_blue.strokeColor = "blue";
style_blue.fillColor = "blue";
// Make Point
coordinates.push(new OpenLayers.Geometry.Point(lon, lat));
var pointsGeometry = new OpenLayers.Geometry.MultiPoint(coordinates);
var pointFeature = new OpenLayers.Feature.Vector(pointsGeometry, null, style_blue);
// Layer
var pointsLayer = new OpenLayers.Layer.Vector("Points Layer");
pointsLayer.addFeatures([pointFeature]);
pMap.addLayer(pointsLayer);
}
Does your map have a 'baselayer'? Otherwise you should add option 'alloverlays'=true to your map options. I'm not sure if this solves your problem though...