Copy link to clipboard
Copied
I just want to duplicate PDF contents into a new layer of an AI file? So how to fast copy? Now I have to open the PDF file and copy pageItems one by one:
var firstLayer = docSrc.activeLayer;
var newLayer = docDest.layers.add();
if (firstLayer.pageItems.length > 0) {
for (var i = firstLayer.pageItems.length - 1; i >= 0; i--) {
var item = firstLayer.pageItems[i];
item.duplicate(newLayer, ElementPlacement.PLACEATBEGINNING);
}
}
Copy link to clipboard
Copied
Duplicating items one by one is the established and most consistent way.
Copy link to clipboard
Copied
Opening a PDF in Illustrator may desroy text and color profiles. Therefore do not open any PDF in Illustrator except those which are created and saved in Illustrator with its editing capabilities.
What you can do: Place a PDF file as linked file, do not embed them. So you can duplicate as any other object.
Copy link to clipboard
Copied
Could you give some sample code to place a PDF file as linked file.
Copy link to clipboard
Copied
how long does it take duplicating items one at a time?
Copy link to clipboard
Copied
It's slow, about 9 - 10s.
Copy link to clipboard
Copied
10 seconds is slow, how many pageItems are you processing?
instead of copying each item you could duplicate the ActiveLayer for an instant gratification. Unfortunately there's no API to duplicate layers.
The good news is that you can record an Action to duplicate layers and play that action with a script using
app.doScript("Action Name", "Action Set Name");
Copy link to clipboard
Copied
A one page pdf?
How about place and embed?
Copy link to clipboard
Copied
Embedding is the same as opening a PDF. As PDFs can have different color spaces and profiles all will be converted or changed to the AI's color space and destroy the colors of the original PDF.
Another problem are the fonts. If the original fonts are not installed some other font will be replaced and text blocks are destroyed and the text appearance might change,