Highlighted

Export Selection as PDF via API

New Here ,
Nov 25, 2019

Copy link to clipboard

Copied

Is there a way to export the current selection in an Illustrator drawing as PDF via the API? We are currently able to achieve a PNG export for the current selection using the following APIs:

 

//the artSet parameter below contains the current selection

sAIRasterize->Rasterize(artSet, &rastSettings, &artBounds, kPlaceInsideOnTop, layerArt, &tempRaster, 0);

AIDataFilter* filter = NULL;

sAIDataFilter->NewFileDataFilter(filePath, "write", 'ART5', 'PICT', &filter);
sAIDataFilter->LinkDataFilter(NULL, filter);

// rasterize art to PNG24 format
sAIImageOpt->MakePNG24(tempRaster, filter, pngParams, MyRasterizeProgressProc);

This will probably not work for exporting as PDF. Is there some other approach we can use to achieve this? As of now, we are forced to copy the current selection, open a new document, paste it into it and export it as PDF. This works but is very expensive. 

 

Any pointers regarding how to directly export the selection to a PDF file will be highly appreciated.

 

 

TOPICS
How to, Import and export, SDK

Views

167

Likes

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

Export Selection as PDF via API

New Here ,
Nov 25, 2019

Copy link to clipboard

Copied

Is there a way to export the current selection in an Illustrator drawing as PDF via the API? We are currently able to achieve a PNG export for the current selection using the following APIs:

 

//the artSet parameter below contains the current selection

sAIRasterize->Rasterize(artSet, &rastSettings, &artBounds, kPlaceInsideOnTop, layerArt, &tempRaster, 0);

AIDataFilter* filter = NULL;

sAIDataFilter->NewFileDataFilter(filePath, "write", 'ART5', 'PICT', &filter);
sAIDataFilter->LinkDataFilter(NULL, filter);

// rasterize art to PNG24 format
sAIImageOpt->MakePNG24(tempRaster, filter, pngParams, MyRasterizeProgressProc);

This will probably not work for exporting as PDF. Is there some other approach we can use to achieve this? As of now, we are forced to copy the current selection, open a new document, paste it into it and export it as PDF. This works but is very expensive. 

 

Any pointers regarding how to directly export the selection to a PDF file will be highly appreciated.

 

 

TOPICS
How to, Import and export, SDK

Views

168

Likes

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
Nov 25, 2019 0
Most Valuable Participant ,
Nov 25, 2019

Copy link to clipboard

Copied

I can say (you probably know this already) that exporting PDF isn't a rasterising process, so you'd need a completely different approach. Indeed, I doubt it exists. You might have to make a temporary document and copy only what is needed, if that is even possible. Also, vector elements and text may be half in and half out of a selection area, and changing their meaning with bounds may also change contents... 

Likes

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
Reply
Loading...
Nov 25, 2019 0
New Here ,
Nov 27, 2019

Copy link to clipboard

Copied

Hello,

   Thank you for the response. As you mention, it is possible to create a temporary document, copy the necessary entities into it and export it to PDF. While this does work, it is an expensive alternative. 

   One of the options we considered was to write an Action which would export the selection as PDF. It is possible to interactively have AI export only the selected elements to PDF. However, when we called the Action from code, it would simply export the whole document instead of the selection for some reason. 

Likes

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
Reply
Loading...
Nov 27, 2019 0
Participant ,
Sep 01, 2020

Copy link to clipboard

Copied

You can try to delete all arts you don't want to export (use AIArtSetSuite::MatchingArtSet to match arts which are not selected), you can also modify artboards to match bounds of the remaining arts. Then do export using action (you already know that part), and then call AIUndoSuite::UndoChanges, to revert changes, try it, i think it is a lot faster than creating temporary document.

Likes

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
Reply
Loading...
Sep 01, 2020 0
New Here ,
Sep 01, 2020

Copy link to clipboard

Copied

Thank you for the response. Yes, this seems to be a good idea, at least in theory. I will try this out and see how it goes.

 

 

Likes

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
Reply
Loading...
Sep 01, 2020 0
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

It is possible to have de full code ? I want to know how I can export the current selection to PNG

Likes

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
Reply
Loading...
Aug 31, 2020 0
New Here ,
Sep 01, 2020

Copy link to clipboard

Copied

There are a couple of ways to go about this:

1) Create an action to export selection to PNG from Illustrator

        Select some content in a file, start recording the action, click File > Export Selection, select the export format as PNG, select scale if needed and click Export, Stop recording. Verify that the action runs correctly by testing it interactively. Then call the action from your code after the content you need to export is selected.

This can be done using the sAIActionManager->PlayActionEvent() function from the SDK.

 

2) Rasterize the content in the selection using the sAIRasterize->Rasterize() function and then export to PNG using the sAIImageOpt->MakePNG24() function on the raster handle. 

Likes

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
Reply
Loading...
Sep 01, 2020 0