27 Replies Latest reply: Nov 19, 2012 2:13 AM by Harsh V Sharma RSS

    Export to PNG from Illustrator

    Community Member
      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.
        • 1. Re: Export to PNG from Illustrator
          Toto RoToTO Community Member
          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.
          • 2. Re: Export to PNG from Illustrator
            Community Member
            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
            • 3. Re: Export to PNG from Illustrator
              A. Patterson Community Member
              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.
              • 4. Re: Export to PNG from Illustrator
                Community Member
                Thanks very much for this info. I will give it a try.
                • 5. Re: Export to PNG from Illustrator
                  Community Member
                  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.
                  • 6. Re: Export to PNG from Illustrator
                    A. Patterson Community Member
                    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.
                    • 7. Re: Export to PNG from Illustrator
                      Community Member
                      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.
                      • 8. Re: Export to PNG from Illustrator
                        Toto RoToTO Community Member
                        Thanks! It'is exactly what i was looking for! :)
                        • 9. Re: Export to PNG from Illustrator
                          Community Member
                          Great. Glad that it has been useful to both of us. And thanks again A. Patterson for the pointer to the header file.
                          • 10. Re: Export to PNG from Illustrator
                            A. Patterson Community Member
                            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! :)
                            • 11. Re: Export to PNG from Illustrator
                              Toto RoToTO Community Member
                              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);
                              }
                              • 12. Re: Export to PNG from Illustrator
                                Community Member
                                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
                                • 13. Re: Export to PNG from Illustrator
                                  Community Member
                                  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.
                                  • 15. Re: Export to PNG from Illustrator
                                    Toto RoToTO Community Member
                                    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.
                                    • 16. Re: Export to PNG from Illustrator
                                      Toto RoToTO Community Member
                                      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.
                                      • 17. Re: Export to PNG from Illustrator
                                        A. Patterson Community Member
                                        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.
                                        • 18. Re: Export to PNG from Illustrator
                                          Community Member
                                          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.
                                          • 19. Re: Export to PNG from Illustrator
                                            Toto RoToTO Community Member
                                            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.
                                            • 20. Re: Export to PNG from Illustrator
                                              Toto RoToTO Community Member
                                              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.
                                              • 21. Re: Export to PNG from Illustrator
                                                Community Member
                                                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.
                                                • 22. Re: Export to PNG from Illustrator
                                                  Community Member
                                                  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));
                                                  • 23. Re: Export to PNG from Illustrator
                                                    Community Member
                                                    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
                                                    • 24. Re: Export to PNG from Illustrator
                                                      Community Member
                                                      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.
                                                      • 25. Re: Export to PNG from Illustrator
                                                        Hitz_M Community Member
                                                        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
                                                        • 26. Re: Export to PNG from Illustrator
                                                          Community Member
                                                          Hitesh,

                                                          Here is my code for saving as PNG. It might help you to work out how to save as JPEG.

                                                          Robin

                                                          extern "C" AIImageOptSuite* sImageOptimization;
                                                          extern "C" AIDataFilterSuite* sAIDataFilter;
                                                          extern "C" AIDocumentSuite* sDocument;
                                                          extern "C" AILayerSuite* sLayer;
                                                          extern "C" AIArtSuite* sAIArt;
                                                          extern "C" AIPathSuite* sAIPath;
                                                          extern "C" AIPathStyleSuite* sAIPathStyle;

                                                          static AIActionParamValueRef CreateRasteriseFileParams ()
                                                          {
                                                          AIActionParamValueRef valueParameterBlock = NULL;
                                                          ReturnIfError (sAIActionManager->AINewActionParamValue (&valueParameterBlock));
                                                          if (valueParameterBlock)
                                                          {
                                                          string theStr ("Adobe PNG Format");
                                                          ReturnIfError (sAIActionManager->AIActionSetString (valueParameterBlock, kAIExportDocumentFormatKey, theStr.c_str ()));
                                                          theStr = "png";
                                                          ReturnIfError (sAIActionManager->AIActionSetString (valueParameterBlock, kAIExportDocumentExtensionKey, theStr.c_str ()));
                                                          }
                                                          return valueParameterBlock;
                                                          }

                                                          static bool gFirstTimePNG = true;
                                                          static AIBoolean MyRasterizeProgressProc (long current, long total)
                                                          {
                                                          return true;
                                                          }

                                                          static void RasteriseFileToPNG (const ai::UnicodeString& inFilePath, AIActionParamValueRef valueParameterBlock, AIArtHandle art, AIRealRect& bounds)
                                                          {
                                                          if (sImageOptimization && sAIDataFilter && art)
                                                          {
                                                          AIDataFilter* dstfilter = NULL;
                                                          AIDataFilter* filter;
                                                          ai::FilePath file (inFilePath);
                                                          AIErr result = sAIDataFilter->NewFileDataFilter (file, "write", 'prvw', 'PNGf', &filter);
                                                          if (!result)
                                                          {
                                                          result = sAIDataFilter->LinkDataFilter (dstfilter, filter);
                                                          dstfilter = filter;
                                                          }

                                                          AIDocumentSetup setup;
                                                          if ((bounds.bottom == 0.0) && (bounds.right == 0.0f))
                                                          {
                                                          if (sDocument->GetDocumentSetup (&setup))
                                                          {
                                                          setup.width = 0.0f;
                                                          setup.height = 0.0f;
                                                          }
                                                          }
                                                          else
                                                          {
                                                          setup.width = bounds.right - bounds.left;
                                                          if (setup.width < 0.0f)
                                                          setup.width = -setup.width;
                                                          setup.height = bounds.bottom - bounds.top;
                                                          if (setup.height < 0.0f)
                                                          setup.height = -setup.height;
                                                          }

                                                          float maxDims = setup.height; // in points
                                                          if (maxDims < setup.width)
                                                          maxDims = setup.width;
                                                          float resolution;
                                                          if (maxDims > 0.0f)
                                                          {
                                                          resolution = 72000.0f / maxDims; // 72 dpi x 1000 pixels = ? dpi X maxDims pixels so ? dpi = 72 dpi x 1000 pixels / maxDims pixels
                                                          if (resolution < 5.0f)
                                                          resolution = 5.0f;
                                                          else
                                                          if (resolution > 300.0f)
                                                          resolution = 300.0f;
                                                          }
                                                          else
                                                          resolution = 36.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 = bounds;
                                                          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;

                                                          AIArtHandle path = NULL;
                                                          AILayerHandle newLayer = NULL;
                                                          result = sLayer->InsertLayer (NULL, kPlaceAboveAll, &newLayer);
                                                          if (newLayer && !result)
                                                          {
                                                          sLayer->SetLayerVisible (newLayer, true); // show layer
                                                          sLayer->SetLayerIsTemplate (newLayer, false); // mark as NOT a template layer so does get exported
                                                          sLayer->SetLayerEditable (newLayer, true);

                                                          AIPathSegment segments[4];
                                                          AIPathStyle pathStyle;
                                                          AIPathStyleMap pathStyleMap;
                                                          result = sAIArt->NewArt (kPathArt, kPlaceAboveAll, NULL, &path);
                                                          if (path && !result)
                                                          {
                                                          result = sAIPath->SetPathSegmentCount (path, 4);
                                                          if (!result)
                                                          {
                                                          segments[0].p.h = bounds.left;
                                                          segments[0].p.v = bounds.top;
                                                          segments[0].in = segments[0].out = segments[0].p;
                                                          segments[0].corner = true;

                                                          segments[1].p.h = bounds.right;
                                                          segments[1].p.v = bounds.top;
                                                          segments[1].in = segments[1].out = segments[1].p;
                                                          segments[1].corner = true;

                                                          segments[2].p.h = bounds.right;
                                                          segments[2].p.v = bounds.bottom;
                                                          segments[2].in = segments[2].out = segments[2].p;
                                                          segments[2].corner = true;

                                                          segments[3].p.h = bounds.left;
                                                          segments[3].p.v = bounds.bottom;
                                                          segments[3].in = segments[3].out = segments[3].p;
                                                          segments[3].corner = true;

                                                          sAIPath->SetPathSegments (path, 0, 4, segments);
                                                          sAIPath->SetPathClosed (path, true);

                                                          sAIPathStyle->GetCurrentPathStyle (&pathStyle, &pathStyleMap);
                                                          pathStyle.fillPaint = false;
                                                          pathStyle.fill.color.kind = kGrayColor;
                                                          pathStyle.fill.color.c.g.gray = kAIRealZero;

                                                          pathStyle.strokePaint = false;
                                                          pathStyle.stroke.color.kind = kGrayColor;
                                                          pathStyle.stroke.color.c.g.gray = kAIRealZero;
                                                          pathStyle.stroke.width = kAIRealZero;
                                                          sAIPathStyle->SetPathStyle (path, &pathStyle);
                                                          }
                                                          }
                                                          }

                                                          result = sImageOptimization->MakePNG24 (art, dstfilter, params, MyRasterizeProgressProc);
                                                          if (dstfilter)
                                                          sAIDataFilter->UnlinkDataFilter (dstfilter, &dstfilter);
                                                          if (path)
                                                          sAIArt->DisposeArt (path);
                                                          if (newLayer)
                                                          sLayer->DeleteLayer (newLayer);
                                                          }
                                                          else
                                                          if (valueParameterBlock)
                                                          {
                                                          ReturnIfError (sAIActionManager->AIActionSetStringUS (valueParameterBlock, kAISaveDocumentAsNameKey, inFilePath));
                                                          ReturnIfError (sAIActionManager->PlayActionEvent (kAIExportDocumentAction, gFirstTimePNG ? kDialogOn : kDialogOff, valueParameterBlock));
                                                          }
                                                          gFirstTimePNG = false;
                                                          }
                                                          • 27. Re: Export to PNG from Illustrator
                                                            Harsh V Sharma Community Member

                                                            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