Export Selection As PDF - Script Help

Community Beginner ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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.

TOPICS
Import and export, Scripting

Views

128

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Mar 18, 2021 Mar 18, 2021
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 = assetIDArr...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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

Best regards

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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

 

 

Best regards

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

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.

 

Best regards

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

This has been a huge help, thankyou very much Charu.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 18, 2021 Mar 18, 2021

Copy link to clipboard

Copied

You're welcome 🙂

Best regards

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines