Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

I have a SVG file with viewBox="-155.7 -99 510 510". I believe this offset the paths in Mac OS X preview by -155.7 -99. when I open the SVG in Illustrator, the paths are not offset at all. how do I export this svg such that:

  1. viewBox="0 0 510 510"
  2. and all the paths have added off set of -155.7 -99

I have tried changing the position of the artboard but the origin of viewbox is never 0,0.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

I did a little research on SVG's and apparently the viewbox is not a element that is exportable via Illustrator. The viewbox element is only compatible with certain programs that chose to use this element or manipulate it. Sadly, Illustrator is not one of them.

If you saved the SVG from Illustrator without "Preserve Illustrator Editing Capabilities" you can reverse the process. Whatever changes you make in the data of the SVG file will then be reflected in Illustrator but through repositioning and resizing both the Artboard and Layers to create a pseudo-viewbox.

For now all you can do is design work in Illustrator and all extra code for offset and positioning of the viewbox within the file data. You can make a pseudo-viewbox by simply changing the Artboards Width + Height/X + Y position and then changing the objects Size and Position attributes as well. But there will never be a true viewbox attribute unless they release an update to Illustrator with editable viewbox features.

Some reading on the SVG Format in Illustrator: Adobe Illustrator Save in SVG Format

share|improve this answer
    
Illustrator does export the viewbox attribute as of Illustrator CC (v 17.x). –  Jakobud Oct 6 at 19:03

I had a very similar problem that my AI created SVG was not centered and expanded to the full browser window, because AI keeps changing the artboard size and forgets about the centering.

The only way to fix it is to have a final manual processing step in Inkscape.

  • open the SVG in Inkscape
  • resize the canvas under File -> Document Properties
  • resize & move your artwork by selecting it and entering the w, h in the toolbar edits

Finally, you have to save the SVG again, but use the format "Optimized SVG" in the Save As dialog. There will be a dialog for SVG options and you have to enable "Enable viewboxing".

As all my SVGs are icons of the same size, this processing step takes only 1 minute as I always have the same canvas and object size. But yes, it is a shame that this step is needed at all and it should be fixed in AI.

share|improve this answer

I've run into this problem several times, and the only thing that has ever worked for me to reliably reset the SVG viewbox to precisely 0, 0 when exporting from Illustrator is to create a new blank document and copy and paste the artwork into it.

The top left corner of this untouched default artboard will export as point 0, 0 of the view box. Use smart guides (cmd-u) or the align window set to Align to Artboard if you need your artwork to start at exactly 0, 0.

You can safely resize the artboard from the bottom right corner, but things start to go wrong if you move the top left corner. Moving the artboards' top left corner or importing SVG files to AI seems to cause some kind of weird internal disconnect between the rulers, artboards and some sort of invisible secret viewbox origin point known only to Illustrator.


AFAICT, as with most things to do with web or emerging technology, Adobe's approach to SVG has been to throw something crudely together so they can boast about it in a press release, then leave it buggy, unfinished and unloved, pretending it doesn't exist and carrying on like it's 1998.

share|improve this answer
    
This does not work for me using Illustrator CC. I've also tried the Fit Artboard to Artwork custom size. The final SVG always has a viewport that is centered. –  wprater Dec 8 '13 at 0:22
1  
Strange - definitely can work in CS6. Must have changed between CS6 and CC - seems like an odd change though. –  user568458 Dec 9 '13 at 9:54
    
@user568458 This is the technique that I also use, not exact but very similar. Any transformations to the 'Artboard' in Illustrator will directly translate to the values of the viewbox being altered on exporting to SVG. You are completely correct in creating a new document and copying over all artwork. Your answer should be marked as correct +1. –  Terry Feb 2 at 19:34
    
Adobe was a big supporter of SVG but that was when svg was emerging they haven't done anything on this front in several years after the Macromedia acquisition because they wanted flash to succeed. –  joojaa Aug 4 at 9:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.