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

Export ai to SVG creating PNG and JPG file

Community Beginner ,
Sep 13, 2023 Sep 13, 2023

Copy link to clipboard

Copied

I have a tool that automates AI. It opens a .ai file and then calls Export passing in AiExportType.aiSVG. I pass in an ExportOptionsSVG object too. When I call Export, I see that I not only get the SVG file created, but I also see either a JPG or PNG file created too. Those filenames are "random" in that the filenames appear to just be hex numbers. For instance, I just got 1338D1F3.jpg for a file. I suspect that the type, jpg or png created may depend on whether there are text frames or not in the .ai file. But, that's just a guess right now. I don't see any option in the APIs for Illustrator.Application, Illustrator.Document or the export options object that would let me stop this from occurring.

 

How can I prevent this from occurring programmatically (via the automation APIs)?

TOPICS
Import and export , SDK

Views

629

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
Community Expert ,
Sep 13, 2023 Sep 13, 2023

Copy link to clipboard

Copied

If you create a new document and draw a plain rectangle with default fill and stroke, then export to svg using your tool, does it create the jpg/png files?

 

if it didn't then, it's probably not the code but the art that is causing the issue

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Regardless of what "causes" this, I want to avoid it. I don't see any API on Artboard or Artboards that would appear to help me avoid these files being created. I do know we have created png files from the .ai files directly via the UI, so that might be why it is insisting on dropping those to disk when I call Export to create the SVG. Indeed, if I don't supress adding the .ai files I open to the MRU and I later open a .ai file later via the UI, Illustrator puts up a message box complaining that it can't find a png file for the .ai file. When our team creates a png from the .ai file, they use the same name and just change the extension. These files created by Export don't use those names, which is probably why Illustrator is saying it can't find the png file.

 

I just want to stop these randomized files being created.

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

I think this is due to the active Artboard. I see there is a Formats section in the Exports For Screens dialog and the "Format" dropdown is set to PNG. I just don't see a way to turn that off programmatically. Also, since I am processing .ai files created by another team, I see that the "Export to:" setting points to a Windows "Users\xxx\Downloads\" folder (xxx is the user name). So, since I don't have the specific user folder, perhaps that is why Illustrator is dropping these unwanted files in the folder where I Export the SVG. Guess I'll have to add code to enum all png and jpg files in that folder before I export and then enum again and remove any new files.

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 Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

I agree you want to avoid it. One way to avoid it is discovering what the cause is, so we can address that.

 

can you provide the script and a file that replicates your issue?

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

I don't see my post with code and the test case?

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

                    Illustrator.Document theDoc = IllustratorApp.Open(theFile, missing, openOptions);// no color space, no options
                        svgOptions.CSSProperties = Illustrator.AiSVGCSSPropertyLocation.aiPresentationAttributes;
                        svgOptions.DocumentEncoding = Illustrator.AiSVGDocumentEncoding.aiUTF8;
                        svgOptions.EmbedRasterImages = false;// Rasters? Rasters? We don't need no stinkin' rasters.
                        svgOptions.CSSProperties = Illustrator.AiSVGCSSPropertyLocation.aiPresentationAttributes;
                        theDoc.Export(theNewFile, Illustrator.AiExportType.aiSVG, svgOptions);

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Hi Carlos,

 

I tried Post a few more times and finally I see it. I don't see the file I tried to attach. "Draft & drop here" doesn't accept the file. I browsed to a file and it showed up on this web page. Seems to go away when I hit Post. Perhaps it just takes time to show up.

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 Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Illustrator files are not supported, but you could save as pdf with Preserve Illustrator Editing Capabilities checked.

 

or you could save your ai file to Google Drive, Dropbox or similar and paste the link here

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 ,
Sep 15, 2023 Sep 15, 2023

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
Community Expert ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

got them, these links work, let me have a look.

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 Expert ,
Sep 15, 2023 Sep 15, 2023

Copy link to clipboard

Copied

ok, 

 

1. your file has a linked image that might be there intentionally or not.

2. This linked image won't cause any issues when you export to svg, it will remain linked whether EmbedRasterImages is set to true or false

missingLink.png

 

3. I don't have the linked image so I replaced that with one I have. 

4. now if I embed the image and export to svg with EmbedRasterImages set to "false", then the image will be "unembedded", in other words, it will be saved to disk along with the svg.

 

so, set EmbedRasterImages = true, or if the link is not supposed to be there, then sort that out before exporting to svg

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 ,
Sep 21, 2023 Sep 21, 2023

Copy link to clipboard

Copied

Thanks Carlos. I set embed raster images to false as we just want SVG without any raster. I added code to detect when a raster file is saved to disk during Export and I delete the file afterwards. I'll see if I can find the linked image and perhaps remove it before calling Export. If not, this will be no big issue as my tool will delete the file (or not) based on a checkbox on my form. I did spin thru the raster images collection on every Layer and add a call to get the File property. I found that just genereated exceptions (which I catch) with a message that no file exists. That was surprising just a bit as I thought the returned string would just be empty. In any case, this issue is solved as I know most of our images are created by the UI team as they are converting PNG and other image formats we have into .ai so we can create SVG from them. They just have the raster image in the .ai file as a reference as they do this conversion. 

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 ,
Sep 21, 2023 Sep 21, 2023

Copy link to clipboard

Copied

LATEST

Hm. E-mail said I shoudl mark as "correct". I see "Upvote Trasnlate Report and Follow". So, I guessed Upvote is the same as "correct" so I cliked it. Hope that is right.

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 Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

what's that? dot net? c#?

 

I won't be able to test but I can replicate the code with javascript or vba, I just need your file to test.

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 ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

Your upload won't even let me send a .zip file. Doesn't support the extension. And, when I try to upload the .ai file, it says it isn't really a .ai file. See if you can get it via my link:

 

https://siemensnam-my.sharepoint.com/:u:/r/personal/rd_holland_siemens_com/Documents/Assembly2_32.ai...

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 Expert ,
Sep 14, 2023 Sep 14, 2023

Copy link to clipboard

Copied

no, I can't get it, the link takes me to a Siemens login page

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