> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/conversion/convert-svg-to-pdf.md).

# Convert SVG to PDF on Server/Desktop

Convert SVG 1.1 documents to PDF seamlessly with Apryse SDK. Learn about supported SVG flavors, color spaces, sizing options, and more for efficient conversion. The Apryse Server SDK streamlines secur

The Apryse SDK 9.5 or later can be used to convert SVG 1.1 documents to PDF without any external dependencies.

## Usage

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
using (PDFDoc doc = new PDFDoc()){
    pdftron.PDF.Convert.FromSVG(doc, input_file_path + intput_file_name, null);
    doc.Save(output_file_path + output_file_name, SDFDoc.SaveOptions.e_remove_unused);
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
PDFDoc doc;
Convert::FromSVG(doc, input_file_path + input_file_name);
doc.Save(output_file_path + output_file_name, SDF::SDFDoc::e_linearized, NULL);
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
PDFDoc doc = new PDFDoc();
Convert.FromSVG(doc, input_file_path + input_file_name, null);
doc.save(output_file_path + output_file_name, SDFDoc.SaveMode.LINEARIZED, null);
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
async function main() {
  const doc = await PDFNet.PDFDoc.create();
  await PDFNet.Convert.FromSVG(doc, input_file_path + input_file_name, null);
  await doc.save(output_file_path + output_file_name, PDFNet.SDFDoc.SaveOptions.e_linearized);
}
PDFNet.runWithCleanup(main);
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
doc = PDFDoc()
Convert.FromSVG(doc, input_path + inputFileName, None)
doc.Save(output_path + outputFileName, 0)
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Dim doc As PDFDoc = New PDFDoc()
pdftron.PDF.Convert.FromSVG(doc, input_path & input_file_name, Nothing)
doc.Save(output_path & output_file_name, SDFDoc.SaveOptions.e_remove_unused)
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
doc = PDFDoc.new
Convert.FromSVG(doc, input_path + inputFileName)
doc.Save(output_path + outputFileName, 0)
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
doc := NewPDFDoc()
ConvertFromSVG(doc, inputPath + inputFileName)
doc.Save(output_file_path + output_file_name, uint(SDFDocE_linearized))
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Supported SVG Flavors

The Apryse SDK accepts SVG graphics as follows:

* SVG 1.1 (Second Edition) as published by the W3C.
* The following Unicode formats and encodings are supported: UTF-8, UTF-16, ISO 8859-1 ... ISO 8859-15, ASCII
* CSS styling is available, but some CSS elements are unsupported.
* In addition to SVG files in plain text format Flate-compressed SVG files (\*.svgz) are supported.
* Colors can be specified with additional color spaces according to the SVG Color 1.2 draft (see [SVG Color Extension](#svg-color-extension)).

See [Unsupported SVG Features](#unsupported-svg-features) for restrictions.

## Size of SVG Graphics

SVG graphics specify the width and height in the svg element which defines the mapping of the SVG graphics to the target viewport (e.g. the browser window or some part of a PDF page). Often the size of the viewport is specified in absolute units, e.g.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<svg xmlns="http://www.w3.org/2000/svg" width="640mm" height="480mm">
```

{% endcode %}
{% endtab %}
{% endtabs %}

If the size is specified in pixels (`px`) the Apryse SDK uses 1pt=1px. These values are also used to calculate the object box for fitting operations. The `svg` element may also contain the `viewBox` attribute which specifies a window inside the viewport. You can override the size values specified in the SVG graphics file with the `SetForcedWidth()` and `SetForcedHeight()` methods of the `SVGConvertOptions` class.

### SVG graphics without absolute size information

Some SVG graphics do not contain absolute size information since `width` and `height` are missing or contain only relative values such as in the following example:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
```

{% endcode %}
{% endtab %}
{% endtabs %}

This is used for SVG graphics which are not intended for standalone use. If no absolute size information is available in the SVG graphics you can specify the desired dimensions via the `SetFallbackWidth()` and `SetFallbackHeight()` methods of the `SVGConvertOptions` class. In the fallback width and height are not set the bounding box of the SVG graphics is calculated automatically. By default the calculated bounding box is moved such that the graphics is located at the original position in the coordinate system (i.e. the box does not necessarily use the origin as corner).

## Font Selection

### Font selection algorithm

Font selection in SVG is controlled by the following properties:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
font-family
font-style
font-weight

font-stretch
font-variant
font-size
font-size-adjust
```

{% endcode %}
{% endtab %}
{% endtabs %}

Only the first three of these properties are relevant for selecting an external font. In order to select a suitable font, the following font names are constructed:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
<font-family>,<font-weight>,<font-style>
<font-family>-<font-weight><font-style>
<font-family>,<font-normweight>,<font-style>
<font-family>,<font-weight>,<font-normstyle>
<font-family>,<font-normweight>,<font-normstyle>
```

{% endcode %}
{% endtab %}
{% endtabs %}

where `<font-normweight>` is one of

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
Regular, Thin, Extralight, Light, Medium, Semibold, Bold, Extrabold, Black
```

{% endcode %}
{% endtab %}
{% endtabs %}

and `<font-normstyle>` is

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
Italic
```

{% endcode %}
{% endtab %}
{% endtabs %}

For example, with the following SVG font specification:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
font-family="Tahoma" font-weight="Bold" font-style="Italic"
```

{% endcode %}
{% endtab %}
{% endtabs %}

The SDK will search for the font `Tahoma,Bold,Italic`. The SDK then tries to load the font names listed above one after the other until the process is successful and a font could be loaded. If all attempts fail, the SDK tries to load the font with the name `<font-family>` and simulates the Bold and Italic properties if required.

The font-family property may also contain multiple font family names, e.g.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
font-family="Georgia, 'Minion Web', 'Times New Roman', Times, 'MS PMincho', serif"
```

{% endcode %}
{% endtab %}
{% endtabs %}

In this case the SDK tries to load the next font in the list if a particular font family could not be loaded. If some font for a `font-family` list could be loaded, the SDK attempts to load the remaining `font-families` in the list as fallback fonts for the first loaded font. If the master font already has fallback fonts because it has been loaded earlier, the new fallback fonts will be appended to the list of existing fallback fonts.

### Mapping generic SVG font families to PDF core fonts

The SDK automatically maps the generic SVG font families `monospace`, `sans-serif` and `serif` to the Latin core fonts at the first occurrence of a generic SVG font family. The full list of generic font name mappings is as follows (there are no default mappings for the generic font families `cursive` and `fantasy`):

| Generic font name      | PDF core font name    |
| ---------------------- | --------------------- |
| monospace              | Courier               |
| monospace,Bold         | Courier-Bold          |
| monospace,Italic       | Courier-Oblique       |
| monospace,Bold,Italic  | Courier-BoldOblique   |
| sans                   | Helvetica             |
| sans,Bold              | Helvetica-Bold        |
| sans,Italic            | Helvetica-Oblique     |
| sans,Bold,Italic       | Helvetica-BoldOblique |
| sans-serif             | Helvetica             |
| sans-serif,Bold        | Helvetica-Bold        |
| sans-serif,Italic      | Helvetica-Oblique     |
| sans-serif,Bold,Italic | Helvetica-BoldOblique |
| serif                  | Times-Roman           |
| serif,Bold             | Times-Bold            |
| serif,Italic           | Times-Italic          |
| serif,Bold,Italic      | Times-BoldItalic      |

## Dealing with missing Fonts and missing Glyphs

### Missing fonts and the default font

If all font loading attempts fail, the SDK attempts to load a default font which was specified via the `SetDefaultFontFamily()` method of the `SVGConvertOptions` class. By default, the `Arial Unicode MS` font is used if available, and `Helvetica` otherwise. It is highly recommended to either make the `Arial Unicode MS` font available, or to specify another font with a large glyph complement via `SetDefaultFontFamily()`.

### Missing glyphs

If a selected font does not contain a required glyph, no text will be visible for that glyph.

### Specifying a global fallback font family

The `SetFallbackFontFamily()` method of the `SVGConvertOptions` class can be used to specify a family of fallback fonts. SVG style attributes will be applied to this font family name, assuming that style variants of the specified font family are actually available.

## SVG Color Extension

SVG by default uses the sRGB color space for text and vector graphics. Embedded images in SVG may use other color spaces, though. For example, an embedded or referenced JPEG image may use the CMYK color space with or without an ICC profile.

In addition to sRGB the SDK supports additional color spaces using syntax extensions according to the SVG Color 1.2 draft specification. The following table lists supported SVG color spaces along with syntax examples:

| color space     | SVG syntax examples                                                                                                              | notes                                                                                               |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| sRGB            | `#FF0000`                                                                                                                        | SVG 1.1 default color space                                                                         |
| ICC-based color | `#7F7F7F icc-color(gray.icc, 0.5)` `#CC6633 icc-color(rgb.icc, 0.8, 0.4, 0.2)` `#2B7FAB icc-color(cmyk.icc, 0.8, 0.4, 0.2, 0.0)` | One, three or four color values must be supplied for Grayscale, RGB or CMYK profiles, respectively. |
| CIELab          | `#598237 cielab(50, -25, 35)`                                                                                                    |                                                                                                     |
| CIELch          | `#FF007E cielch(50, 127, 0)` `#FF007E cielchab(50, 127, 0)`                                                                      | Lightness, chroma and hue (in degrees) are converted to CIELab.                                     |
| n-colorant      | `#FFE560 device-nchannel(0, 0.7, 0.2)` `#FFF36D device-nchannel(1 0 0 0 0.5 0.2 0)`                                              | The sRGB fallback color is used.                                                                    |

SVG syntax requires sRGB fallback colors for all variants. The SDK uses the fallback color in case of syntax errors, missing ICC profiles or if the option `SetForceSRGB(true)` was set via the `SVGConvertOptions` class.

### ICC-based colors

The ICC-based color specifications apply the specified ICC profile which is searched in the SDK's configured resource search path. ICC profiles are ignored if the option `SetHonorIccProfile(false)` was set via the `SVGConvertOptions` class.

### Gray, RGB and CMYK device color spaces

Device-dependent color spaces are supported with the `device-gray`, `device-rgb` and `device-cmyk` keywords.

### DeviceN colors

The `device-nchannel` syntax can be used to specify DeviceN colors, but these specifications are ignored in general and the sRGB fallback color is used.

### Shadings

The color spaces listed above can also be used in SVG gradients. However, PDF requires all stop colors for a gradient to be taken from the same color space. If a gradient uses stop colors from different color spaces the sRGB fallback colors for all stop colors are used.

## SVG Contents beyond Vector Graphics and Text

The SDK processes the image element in SVG and accepts JPEG and PNG images as well as nested SVG graphics. Image data may be embedded in the SVG file or located in an external file.

If an image is not available (e.g. because the referenced external image file is missing), the SDK creates a transparent gray checkerboard pattern.

## Unsupported SVG Features

### Treatment of unsupported features

Unsupported SVG features are ignored. As a result, output is created but some aspects of the graphics may be missing or wrong.

### Hyperlinks and network resources

SVG files can contain hyperlinks that can be presented to a user as clickable hyperlinks by an SVG viewer, e.g. in a web browser. Hyperlinks are not imported by the SDK.

SVG graphics may reference external resources such as fonts or images via URLs in the graphics file. The SDK does not support retrieval of remote resources. All external resources referenced by an SVG file must be available locally.

### Unsupported SVG elements

The following SVG elements are not supported and are ignored:

* elements for animation and scripting: `animate`, `animateColor`, `animateMotion`, `animateTransform`, `script`, `mpath`, `set`
* elements for filters: `feBlend`, `feColorMatrix`, `feComponentTransfer`, `feComposite`, `feConvolveMatrix`, `feDiffuseLighting`, `feDisplacementMap`, `feDistantLight`, `feFlood`, `feFuncA`, `feFuncB`, `feFuncG`, `feFuncR`, `feGaussianBlur`, `feImage`, `feMerge`, `feMergeNode`, `feMorphology`, `feOffset`, `fePointLight`, `feSpecularLighting`, `feSpotLight`, `feTile`, `feTurbulence`, `filter`
* other elements: `cursor`, `foreignObject`, `vkern`

### Restricted SVG elements, attributes and properties

The following attributes and properties are subject to restrictions:

* Some CSS directives are not supported.
* The font selection property `font-variant` is supported only with the keyword `smallcaps`, and only for fonts containing the OpenType feature `smcp`.
* Combination of values of the text presentation property `text-decoration` are not supported. The SDK doesn’t draw the decoration elements as areas with separate fill and stroke color, but draws the decorations as lines. The lines are drawn with the fill color if present, otherwise with the stroke color.
* The attribute `rotate` for the `textPath` element is not supported.
* The property `unicode-bidi` is honored only for TrueType/OpenType fonts containing the required tables for Bidi text layout.
* The property `glyph-orientation-vertical` is supported according to SVG 1.1 except the angles 180˚ and 270˚ which are not supported.
* The attribute `preserveAspectRatio` for the `view` element is ignored.
* The property `overflow` for the `svg` element does not support the value `visible` if a Form XObject is created, i.e. overflowing content is clipped. This can be avoided by setting `SetInline(true)` via the `SVGConvertOptions` class, which is the default.

### Unsupported SVG properties

The following SVG properties are not supported and are ignored: `alignment-baseline`, `color-interpolation`, `color-interpolation-filters`, `color-rendering`, `cursor`, `dominant-baseline`, `enable-background`, `filter`, `flood-color`, `flood-opacity`, `glyph-orientation-horizontal`, `image-rendering`, `lighting-color`, `pointer-events`, `shape-rendering`, `text-rendering`

### Unsupported attributes of supported SVG elements

The following attributes of supported SVG elements are not supported and are ignored:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
baseProfile (svg)
contentScriptType (svg)
contentStyleType (svg)
externalResourcesRequired (all elements)
method (textPath)
on* (all elements)
spacing (textPath)
textLength and lengthAdjust for vertical text (text, textpath, tref, tspan)
version (svg)
zoomAndPan (svg)
xlink:role (all elements)
xlink:show (all elements)
xlink:type (all elements)
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/conversion/convert-svg-to-pdf.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
