Insert SVG image (or SVG code)

I am trying to insert a SVG image into a page (and then export the whole project as Epub), but Scrivener 3.2.2 does not accept it. Instead, it shows only a link to the SVG file on my HD.

Can it be done?

Are you using the Export feature, or the Compile command?

Does Compiling to other formats (PDF, Word) give the results you want?

I think Scrivener only accepts JPG, PNG (maybe TIFF and GIF), basically raster formats, which I believe get reformatted to PNG internally, so an SVG won’t import.

I haven’t tried it, but if you have access to the SVG code you could try pasting that in, marking it with Format → Preserve Formatting, which MD will then treat as raw code on the way to ePub. But whether ePub will then display it as a graphic is well beyond my experience and expertise!

Hope that helps. :slight_smile:

Mark

1 Like

You are my hero! I did what you said, and it works! The Epub shows the SVG image. Thank you!

So, for the record:

Paste the SVG code into the page and mark it with “Format → Preserve formatting”.

Then give it a style: “Style → New style from selection”.

Then add the CSS in “Compile → Formats → CSS → Custom Stylesheet”.

1 Like

Really glad it worked. If ever I need to create an ePub and want to include SVG graphics, I’ll know to come back here and ask you for more details.

:smiley:

Mark

1 Like

I am guessing this is because you are always going to need to be able to target the graphic in CSS to control scaling and such. Is that right?

btw, this is a really nice tip.

When you give the SVG code a style (example: “svg-image”), it will be put inside a <p></p>, like this:

<p class="svg-image"><svg ...

The scaling I set in the SVG code itself:

<svg width="35%" height="35%" ...

In the CSS, I set margins and alignment:

.svg-image { margin: 1.5rem 0rem 1.5rem 0rem; text-indent: 0rem; text-align: center; }

This applies only if you publish your book on Apple Books:

After compiling to Epub, you have to add properties="svg" to the content.opf file. If your SVG in on body1.xhtml, then like this:

<item id="body1" href="body1.xhtml" media-type="application/xhtml+xml" properties="svg"/>

1 Like