Skip navigation
Currently Being Moderated

Export to PNG from Illustrator

Oct 4, 2006 5:57 AM

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.
 
Replies
  • Currently Being Moderated
    May 19, 2008 4:13 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2008 12:10 PM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2008 5:57 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2008 6:42 AM   in reply to (Robin_Landsbert)
    Thanks! It'is exactly what i was looking for! :)
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2008 7:40 AM   in reply to (Robin_Landsbert)
    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! :)
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 12:50 AM   in reply to (Robin_Landsbert)
    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);
    }
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 4:13 AM   in reply to (Robin_Landsbert)
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 4:14 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 4:19 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 7:19 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 24, 2008 8:44 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 25, 2008 12:51 AM   in reply to (Robin_Landsbert)
    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.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 21, 2008 11:24 PM   in reply to (Robin_Landsbert)
    Hi Robin,

    I need to do the same stuff to generate JPEG images.
    Can you tell me the parameters for
    AIErr result = sAIDataFilter->NewFileDataFilter, what should be used in place of 'prvw', 'PNGf' for JPEG.

    Thanks and Regards,
    Hitesh
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 19, 2012 2:13 AM   in reply to (Robin_Landsbert)

    Hi Robin,

     

    I want to generate PNG files from AI..

     

    but in your above code I am not able to understand the following objets:

     

     

    ReturnIfError

    kAIExportDocumentFormatKey

    kAIExportDocumentExtensionKey

    kAISaveDocumentAsNameKey

    kAIExportDocumentAction

     

     

     

    can you please help me..

     

    Thanks

    Harsh

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)