Skip to main content
Known Participant
February 25, 2022
Question

How to fast copy PDF to ai file?

  • February 25, 2022
  • 4 replies
  • 787 views

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);
}
}
This topic has been closed for replies.

4 replies

pixxxelschubser
Community Expert
Community Expert
February 27, 2022

A one page pdf?
How about place and embed?

Willi Adelberger
Community Expert
Community Expert
February 27, 2022

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,

CarlosCanto
Community Expert
Community Expert
February 27, 2022

how long does it take duplicating items one at a time? 

Known Participant
February 28, 2022

It's slow, about 9 - 10s.

CarlosCanto
Community Expert
Community Expert
February 28, 2022

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");

Willi Adelberger
Community Expert
Community Expert
February 27, 2022

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.

Known Participant
February 28, 2022

Could you give some sample code to place a PDF file as linked file.

femkeblanco
Legend
February 27, 2022

Duplicating items one by one is the established and most consistent way.