Copying page content
Ok, this is lots of code for a task that should be simple but I didnt write the API :@
This script copies every item on a src-page to a dst-page and doesnt care if one of them is a master-page. I had to write my own map for that and I'm just missing a tiny bit now: placement. If the original item is a link, I wanted to duplicate the original linked item and link that to the dupe instead. That works now, but the return of contentPlace() seems to be no item and in the API (https://www.indesignjs.de/) I dont find a return Type mentioned.
Also, for some reasons that elude my, orig.remove() does not work and yields the error:
Error Number 1
Error string remove.
WTF?
/* Ancient Adobe-version has no Map() -.- */
function Map() {
this.keys = Array();
this.values = Array();
this.set = function(key, value) {
idx = this.getKeyIdx(key, true);
this.values[idx] = value;
};
this.getKeyIdx = function(key, create) {
for (var i = 0; i< this.keys.length; i++) {
if (this.keys[i] == key)
return i;
}
if (!create)
return undefined;
this.keys.push(key);
return this.keys.length;
};
this.get = function(key) {
idx = this.getKeyIdx(key, false);
if (idx === undefined)
return undefined;
return this.values[idx];
};
}
function copyPageContent(src, dst) {
var itemsOnPage = src.pageItems;
copyMap = new Map();
for (var e = 0; e < itemsOnPage.length; e++) {
orig = itemsOnPage[e];
duped = orig.duplicate(dst);
copyMap.set(orig.id, duped.id);
}
for (var e = 0; e < itemsOnPage.length; e++) {
orig = itemsOnPage[e];
options = orig.linkedPageItemOptions;
if (!options.isValid)
continue;
dupedID = copyMap.get(options.parent.id);
if (dupedID === undefined)
continue;
dupedItem = dst.pageItems.itemByID(dupedID);
parentItem = dupedItem.parent;
gb = orig.geometricBounds;
pos = [gb[1], gb[0]];
newLink = parentItem.contentPlace(dupedItem, true);
newLink.move(pos); // <- this doent work, newLink is no Item.
orig.remove(); // <- this doesent work, even if API mentions remove as an PageItem-function -.-
}
}
How do I move the newly placed content to the position, transformation and scaling of orig before removing it?
