Skip to main content
Participant
March 18, 2021
Answered

Export Selection As PDF - Script Help

  • March 18, 2021
  • 1 reply
  • 1887 views

Hello,

 

I have recenetly come across the following function from this post on the forum:

app.activeDocument.exportSelectionAsPNG(filePath);

I was wondering if something existed along the same lines for exporting selections to PDF?

I have had a look through the docs but I cannot find the function above in the docs anywhere, let alone a PDF option.

 

Any help would be much appreciated. 

Luke.

This topic has been closed for replies.
Correct answer Charu Rajput

Following link will give you some idea for exporting the asset

 

https://community.adobe.com/t5/illustrator/what-s-new-in-illustrator-scripting-cc2018/m-p/9422236

 

 


I just wrote simple script that will export selected items as a PDF. I hope this will help

 

 

var doc = app.activeDocument;
var docAssets = doc.assets;
var assetIDArray = new Array();
var itemToExport = new ExportForScreensItemToExport();
itemToExport.artboards = '';
itemToExport.document = false;
var assetArray = new Array();
for (var i = 0; i < app.selection.length; i++) {
    var asset = docAssets.add(app.selection[i]);
    assetIDArray.push(asset.assetID);
}
itemToExport.assets = assetIDArray;
var options = new ExportForScreensPDFOptions();
app.activeDocument.exportForScreens(File('~/Desktop'), ExportForScreensType.SE_PDF, options, itemToExport);

 

 

Before you run the script, select all items that you want to export. Here is the descrtiption what script do.

 

1. First it will create assets from the selected items.

2. Export all assets as a PDF at Desktop.

 

NOTE: If you run the script second time, it will add assests back to the assets panel so assets will increase. You can handle it by checking if selected element as an assets already exists then don't add inside the Asset panel.

 

1 reply

Charu Rajput
Community Expert
Community Expert
March 18, 2021

Hello,

You can export the document as PDF file. Below is the link with all available options for exporting PDF and with one example at the end.

https://illustrator-scripting-guide.readthedocs.io/jsobjref/PDFSaveOptions/?highlight=PDF 

 

Also, below link will also be helpful

https://community.adobe.com/t5/illustrator/script-export-pdf-en-serie/m-p/11158007

 

 

Best regards
Participant
March 18, 2021

Thanks for the quick response Charu. So from the response I can assume there is no built in function for exporting a selection to a PDF, just an entire document?

 

Cheers.

Charu Rajput
Community Expert
Community Expert
March 18, 2021

You can use, Export Asset functionality to export assets as a PDF.

Best regards