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.
1 Correct answer
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
...
Explore related tutorials & articles
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
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.
Copy link to clipboard
Copied
You can use, Export Asset functionality to export assets as a PDF.
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
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.
Copy link to clipboard
Copied
This has been a huge help, thankyou very much Charu.
Copy link to clipboard
Copied
You're welcome 🙂

