• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Export to PNG from Illustrator

Community Beginner ,
Oct 04, 2006 Oct 04, 2006

Copy link to clipboard

Copied

Does anyone have the AIPNGFormatAction.h header file so I can export Illustrator to PNG. I have found the AIPDFFormatAction.h header and got it working but I need the parameters for setting the resolution of the PNG.
TOPICS
SDK

Views

20.8K

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
Enthusiast ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Hello,

I have got exactly the same problem.
Here it is the snippet for for exporting the current layer of the artwork:

ASErr result;
AIActionParamValueRef valueParameterBlock = NULL;
ActionDialogStatus dialogStatus = kDialogOff;

result = AIActionManager->AINewActionParamValue(&valueParameterBlock);

if (valueParameterBlock)
{
// see AIDocumentation.h

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'name', pathName);

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'frmt', "Adobe PNG Format");

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'extn', "png");

result = sAIActionManager->PlayActionEvent("adobe_exportDocument", dialogStatus, valueParameterBlock);

result = sAIActionManager->AIDeleteActionParamValue(valueParameterBlock);
}

It seems to work! but since the DialogStatusbox is not shown, how could I set programmaticaly export settings for PNG, such as background visibility and resolution.

Any help will be appreciated,
Best regards.

Thomas.

Votes

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 ,
May 19, 2008 May 19, 2008

Copy link to clipboard

Copied

Thomas,

I never solved the issue. Adobe never replied to my emails requesting the header files for export PNG so I could get the parameters. In the end I bypassed the whole issue by exporting as PDF (where I can control all the parameters because I have the header files) and then converting the PDF to PNG using Adobe's PDF library (which we have licenced).

Obviously if you pre-setup the values for resolution etc manually before you run your code it retains the export values but if you have never exported as PNG then it always ends up as 300 dpi.

Let me know if you have any better luck in discovering the parameters for controlling resolution and transparency.

Robin

Votes

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
Guide ,
May 20, 2008 May 20, 2008

Copy link to clipboard

Copied

If you can record the export as an action, you can try saving it as an action set and opening up the resulting .aia file in text editor. It should display all the parameters used by actions for the action set. The only thing it's not super helpful is when a parameter expects a binary block, but the size of the binary block can sometimes point the way to the appropriate struct.

Votes

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 ,
May 21, 2008 May 21, 2008

Copy link to clipboard

Copied

Thanks very much for this info. I will give it a try.

Votes

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 ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

I created an action file for exporting to PNG from Illustrator and opened up the .aia file. Unfortunately it does not look like the action contains any parameters for resolution or transparency. I deciphered all the hex strings and 4 byte commands and it only contains the standard parameters for file name and location, format and extension. It may be an oversight by Adobe that it just uses the last setting when exporting.

Votes

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
Guide ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

Interesting -- there wasn't a binary parameter in there? I assumed there'd b a struct of some sort for handling export-to-PNG options.

Have you looked at AIImageOptimization.h? There seems to be a way to rasterize art to a PNG using AIImageOptPNGParams, but maybe you've looked at this and ruled it out.

Votes

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 ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

AIImageOptimization.h looks much more promising. The AIImageOptPNGParams has the parameters for resolution and alpha and even width and height so this should be perfect. Thank you again for the pointer.

Votes

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
Enthusiast ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

Thanks! It'is exactly what i was looking for! :)

Votes

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 ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

Great. Glad that it has been useful to both of us. And thanks again A. Patterson for the pointer to the header file.

Votes

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
Guide ,
Jun 11, 2008 Jun 11, 2008

Copy link to clipboard

Copied

I hope it works out -- if there's anything I've learned from getting to know this API is that there is a *ton* of great stuff in there, but for some reason a lot of it is named about as unintuitively as you could imagine! :)

Votes

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
Enthusiast ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

For information I find a workaround to export art as png, using 'ai_plugin_rasterize' and 'adobe_exportDocument' commands.

First of all, art is rasterized using 'ai_plugin_rasterize' command.
I used action scripts, as you told me, to 'hack' adobe' command. Command is used as follow:

ASErr result1;
AIActionParamValueRef valueParameterBlock1 = NULL;
ActionDialogStatus dialogStatus1 = kDialogOff;

result1 = sAIActionManager->AINewActionParamValue(&valueParameterBlock1);
if (valueParameterBlock1)
{
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1668246642, "CMJN");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1685088558, "72");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1651205988, "1");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1954115685, "0");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1634494763, "1");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1835103083, "0");
result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1885430884, "0.0");

result1 = sAIActionManager->PlayActionEvent("ai_plugin_rasterize", dialogStatus1, valueParameterBlock1);
result1 = sAIActionManager->AIDeleteActionParamValue(valueParameterBlock1);
}

This is hardcore and awful coding! 😉 all keys are cuted and pasted directly from action script I have made, and values iare directly written in that method.

Parameter 1 : Color Model. (enumerated)
Parameter 2 : Resolution. (integer)
Parameter 3 : Background (enumerated)
Parameter 4 : (enumerated)
Parameter 5 : Do not know the correct translation in English, "Lissage" mode in french in the text. (enumerated)
Parameter 6: Create a mask (boolean)
Parameter 7 : add point around art.(unit real)

Then adobe_exportDocument is called.
As it shown above, command is called like that:

ASErr result;
AIActionParamValueRef valueParameterBlock = NULL;
ActionDialogStatus dialogStatus = kDialogOff;

result = AIActionManager->AINewActionParamValue(&valueParameterBlock);

if (valueParameterBlock)
{

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'name', pathName);

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'frmt', "Adobe PNG Format");

result = sAIActionManager->AIActionSetString(valueParameterBlock, 'extn', "png");

result = sAIActionManager->PlayActionEvent("adobe_exportDocument", dialogStatus, valueParameterBlock);

result = sAIActionManager->AIDeleteActionParamValue(valueParameterBlock);
}

Votes

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 ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

This is just the code I was originally looking for. Thank you for sharing this with us. To clean up your code a bit I have converted your numbers into hex and then into characters so it is more readable. So 1668246642 = 0x636F6C72 = 'colr' as 0x63 is the ASCII code for a 'c', 0x6F = 'o', 0x6C = 'l' and 0x72 = 'r'. Here are the rest:

1668246642 = 0x636F6C72 = 'colr'
1685088558 = 0x6470692E = 'dpi.'
1651205988 = 0x626B6764 = 'bkgd'
1954115685 = 0x74797065 = 'type'
1634494763 = 0x616C692B = 'ali+'
1835103083 = 0x6D61736B = 'mask'
1885430884 = 0x70616464 = 'padd'

Also "Lissage" means "Smoothing" or "Anti-alias" in English.

Thank you again. I will give it a try.

Robin Landsbert

Votes

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 ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

I have tried your code and the

result1 = sAIActionManager->PlayActionEvent("ai_plugin_rasterize", dialogStatus1, valueParameterBlock1);

does not seem to work unless you select all before the call.

result1 = sAIActionManager->PlayActionEvent(kAISelectAllAction, kDialogOff, NULL);

Any ideas? The ai_plugin_rasterize module says that there is an invalid selection in the PlayActionEvent call.

Votes

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
Enthusiast ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

Votes

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
Enthusiast ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

Exaclty, I forgot to explain the fact that Art must be selected before rasterizing and exporting it. This stuff is done is elsewhere in my code.

A helper class does this stuff.

Here it is how I do. (It works, but I do not tell that is the way it should be done 😉 )

first: I insert a temp layer in the Artwork tree.
then : duplicate art you want to be exported and add it to tempLayer, and set its selection state. (See Art suite and setUserAttributes.)
after: hide all others layers
and finally: call commands, dispose duplicated art and delete temp layer.
roll back to previous state for all layers.

Thomas.

Votes

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
Enthusiast ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

thanks for giving me key name. :)
I didn't assume the fact that keys were in decimal.

ps: we could also use the Rasterize suite, and then export the result.

Votes

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
Guide ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

On that note, it's even possible to rasterize the result using AIRasterize & pull out the raw image data. We use that in our product to push the data into the format our GUI needs to display some of results.

Votes

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 ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

I have finally got round to testing my code and it seems to make no difference to the resolution. I want to produce a PNG as near to 1000x1000 pixels as possible so I alter the resolution to a value so that docWidth (in inches) X resolution == 1000. I set:

result1 = sAIActionManager->AIActionSetString(valueParameterBlock1, 1685088558, resolutionStr.c_str());

where resolutionStr is the string of the INTEGER that I have calculated and then I call

result = sAIActionManager->PlayActionEvent("adobe_exportDocument", dialogStatus, valueParameterBlock);

But my PNG still comes out in the resolution of the last MANUAL export using the dialog.

I will look at the Rasterize Suite. It looks more promising.

Votes

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
Enthusiast ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

I found the problem.
dpi value is not a char* but an int, so I have to use:
sAIActionManager->AIActionSetInteger(valueParameterBlock1, 1685088558, 15);

param 1, 3, 4, 5: sAIActionManager->AIActionSetEnumerated(....)
param 6: sAIActionManager->AIActionSetBoolean(......)
param 7: sAIActionManager->AIActionSetUnitReal(.....)

For debugging, I did not hide dialog status, to see if values were modified, and I realized that parameters were not set correctly.
(dpi parameter was always set to 1, whatever value was set.)

sorry for telling you mistakes. :(
hope this will more usefull.

Votes

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
Enthusiast ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

Let's try with that. Let me know if it works ? it should...but we never know.


if (valueParameterBlock1)
{

result1 = sAIActionManager->AIActionSetEnumerated(valueParameterBlock1, 'colr', "AIRasterizeType", 5);
result1 = sAIActionManager->AIActionSetInteger(valueParameterBlock1, 'dpi.', 10);
result1 = sAIActionManager->AIActionSetEnumerated(valueParameterBlock1, 'bkgb', "AITransparencyGrid", 0);
//result1 = sAIActionManager->AIActionSetEnumerated(valueParameterBlock1, 'type', ....);
result1 = sAIActionManager->AIActionSetEnumerated(valueParameterBlock1, 'alis', "AIResamplingType", 0);
result1 = sAIActionManager->AIActionSetBoolean(valueParameterBlock1, 'mask', true);
result1 = sAIActionManager->AIActionSetUnitReal(valueParameterBlock1, 'padd', unitDistance, 0.0);

result1 = sAIActionManager->PlayActionEvent("ai_plugin_rasterize", dialogStatus1, valueParameterBlock1);
result1 = sAIActionManager->AIDeleteActionParamValue(valueParameterBlock1);
}

'type' parameter is not set yet. I did not find how to set correctly this parameter but I am still working on that.

Votes

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 ,
Jun 26, 2008 Jun 26, 2008

Copy link to clipboard

Copied

I have been playing around with the "ai_plugin_rasterize" action and it seems to have nothing to do with exporting to PNG. It invokes the Object->Rasterize menu command which takes the selected graphical objects and rasterizes them to a bitmap which it the uses to replace the selected objects with. I did your trick of using kDialogOn to see what was happening and that is when I discovered that I was invoking the wrong command.

I can still find no way to change the options in the Export to PNG dialog. I tried passing some of the parameters into the valueParameterBlock of the sAIActionManager->PlayActionEvent (kAIExportDocumentAction, kDialogOff, valueParameterBlock); but it made no difference. Back at square 1.

Votes

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 ,
Jun 26, 2008 Jun 26, 2008

Copy link to clipboard

Copied

I have looked into the code of the Export to PNG plug-in and found the following strings in the code:

ai_plugin_PNGFileFormat
PNG File Format
Adobe PNG Format
AIPNGFileFormatScratchSpaceKey
PNGFileFormat
Resolution
OtherResolution
Background/red
Background/green
Background/blue
AntiAlias
Interlaced

The string "Adobe PNG Format" above is used with:

sAIActionManager->AIActionSetString (valueParameterBlock, kAIExportDocumentFormatKey,"Adobe PNG Format");

and 'ai_plugin_PNGFileFormat' looks like it could be the first parameter for PlayActionEvent although I am actually using 'adobe_exportDocument'

So it looks like there are some parameters that can be passed into the plug-in but I don't know how to do it. Is there some call like:

sAIActionManager->AIActionSetNamedParameter(valueParameterBlock, "OtherResolution", 36));
sAIActionManager->AIActionSetNamedParameter(valueParameterBlock, "AntiAlias", 1));
sAIActionManager->AIActionSetNamedParameter(valueParameterBlock, "Interlaced", 0));

Votes

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 ,
Jun 27, 2008 Jun 27, 2008

Copy link to clipboard

Copied

I have written the following code which ALMOST works...

extern "C" AIDocumentSuite* sDocument;
extern "C" AIImageOptSuite* sImageOptimization;
extern "C" AIDataFilterSuite* sAIDataFilter;

static AIBoolean MyRasterizeProgressProc (long current, long total)
{
}

static void RasteriseFile (const string& inFilePath, AIArtHandle art)
{
if (sImageOptimization && sAIDataFilter && sDocument && art && inFilePath.length ())
{
AIDataFilter* dstfilter = NULL;
AIDataFilter* filter;
ai::UnicodeString theUnicode (inFilePath, kAIPlatformCharacterEncoding);
ai::FilePath file (theUnicode);
AIErr result = sAIDataFilter->NewFileDataFilter (file, "write", 'prvw', 'PNGf', &filter);
if (!result)
{
result = sAIDataFilter->LinkDataFilter (dstfilter, filter);
dstfilter = filter;
}
float resolution = 36.0f;
AIDocumentSetup setup;
if (!sDocument->GetDocumentSetup (&setup))
{
float maxDims = setup.height; // in points
if (maxDims < setup.width)
maxDims = setup.width;
resolution = 72000.0f / maxDims; // want the PNG to be a max of 1000 pixels
if (resolution < 5.0f)
resolution = 5.0f;
else
if (resolution > 300.0f)
resolution = 300.0f;
}
else
{
setup.width = 0.0f;
setup.height = 0.0f;
}
AIImageOptPNGParams2 params;
params.versionOneSuiteParams.interlaced = false;
params.versionOneSuiteParams.numberOfColors = 255;
params.versionOneSuiteParams.transparentIndex = 0;
params.versionOneSuiteParams.resolution = resolution;
params.versionOneSuiteParams.outAlpha = false;
params.versionOneSuiteParams.outWidth = 0;
params.versionOneSuiteParams.outHeight = 0;
params.antialias = true;
/* A cropping box for the art. If empty or degenerate, do not crop. */
params.cropBox.left = 0.0f;
params.cropBox.top = 0.0f;
params.cropBox.right = setup.width / 72.0f * resolution;
params.cropBox.bottom = setup.height / 72.0f * resolution;
params.backgroundIsTransparent = true;
/* When backgroundIsTransparent is false, rasterize against this matte color. */
params.matteColor.red = 1.0f;
params.matteColor.green = 1.0f;
params.matteColor.blue = 1.0f;

result = sImageOptimization->MakePNG24 (art, dstfilter, params, MyRasterizeProgressProc);
if (dstfilter)
sAIDataFilter->UnlinkDataFilter (dstfilter, &dstfilter);
}
}

It allows me to adjust the resolution but now it seems to optimise the PNG image size to just include the bounds of the art on the layer despite me giving it a clipping rect in the param block. I think my only alternative is to add a rectangle the size of the page with no fill and no frame. I will let you know I I get on.

Robin Landsbert

Votes

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 ,
Jun 27, 2008 Jun 27, 2008

Copy link to clipboard

Copied

Adding a new layer, then adding a box with no fill and no frame the size of the page and rendering to PNG worked fine. I then delete the box and the layer when I am done. Problem solved. Thank you everyone for the various pointers.

Votes

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