---
Product: barcode
Platform: python
Page Type: kb
Canonical URL: https://kb.aspose.org/barcode/python/how-to-render-barcode-python
Last Updated: 2026-07-09
---

# How to Render Barcodes with Aspose.BarCode FOSS

Render barcodes to SVG and PNG using RenderOptions to control scale, DPI, colors, quiet zone, and human-readable text in Aspose.BarCode FOSS for Python.

## Problem

After generating a barcode, you need to render it as an image file. Aspose.BarCode FOSS for Python renders barcodes to SVG and PNG formats via the `to_svg()` and `to_png()` methods on the `Barcode` object. The `RenderOptions` class controls visual properties such as scale, DPI, colors, quiet zone, and human-readable text display.

```python
import aspose_barcode_foss as barcode
from aspose_barcode_foss import RenderOptions

bc = barcode.code128("RENDER-ME")
png = bc.to_png(options=RenderOptions(scale=2.0, dpi=300))
```

## Prerequisites

- Python 3.12 or later
- pip package manager
- `aspose-barcode-foss` built from source

## SVG Output

Call `to_svg()` to get the barcode as an SVG string. SVG output is vector-based and scales without quality loss.

```python
import aspose_barcode_foss as barcode

bc = barcode.qr("https://example.com")
svg_string = bc.to_svg()

with open("barcode.svg", "w") as f:
    f.write(svg_string)
```

## PNG Output

Call `to_png()` to get the barcode as PNG bytes. PNG output is rasterized at the specified scale and DPI.

```python
import aspose_barcode_foss as barcode

bc = barcode.code128("PNG-OUTPUT")
png_bytes = bc.to_png()

with open("barcode.png", "wb") as f:
    f.write(png_bytes)
```

## Controlling Scale and DPI

Use `RenderOptions` to set `scale` (a float multiplier for module size) and `dpi` (dots per inch for raster output). You can also set `module_width` and `module_height` directly for precise control over individual module dimensions.

```python
from aspose_barcode_foss import RenderOptions

options = RenderOptions(
    scale=3.0,
    dpi=300,
    module_width=1.5,
    module_height=25.0,
)
png = bc.to_png(options=options)
```

## Setting Colors

Set `foreground_color` and `background_color` as CSS color strings. Use `transparent_background=True` for PNG output with no background fill.

```python
from aspose_barcode_foss import RenderOptions

options = RenderOptions(
    foreground_color="#003366",
    background_color="#FFFFFF",
)
svg = bc.to_svg(options=options)

# Transparent background for PNG
options_transparent = RenderOptions(
    foreground_color="#000000",
    transparent_background=True,
)
png = bc.to_png(options=options_transparent)
```

## Quiet Zone

The `quiet_zone` property controls the whitespace margin around the barcode in module units. Barcode standards typically require a minimum quiet zone for reliable scanning.

```python
from aspose_barcode_foss import RenderOptions

options = RenderOptions(quiet_zone=10.0)
svg = bc.to_svg(options=options)
```

## Human-Readable Text

Set `show_text=True` to render human-readable text below the barcode. Control the font with `font_family` and `font_size`.

```python
from aspose_barcode_foss import RenderOptions

options = RenderOptions(
    show_text=True,
    font_family="monospace",
    font_size=12.0,
)
svg = bc.to_svg(options=options)
```

## RenderOptions Properties

| Property | Type | Description |
|----------|------|-------------|
| `scale` | `float` | Multiplier for module size |
| `dpi` | `int` | Dots per inch (raster output) |
| `module_width` | `float` | Width of one module |
| `module_height` | `float` | Height of one module |
| `quiet_zone` | `float` | Whitespace margin in module units |
| `foreground_color` | `str` | CSS color for bars/modules |
| `background_color` | `str` | CSS color for background |
| `transparent_background` | `bool` | Transparent PNG background |
| `show_text` | `bool` | Show human-readable text |
| `font_family` | `str` | Font for human-readable text |
| `font_size` | `float` | Font size for human-readable text |

## Known Limitations

The `to_pdf()` method and `PdfRenderer` class exist in the API but raise `NotImplementedError`. Use `to_svg()` or `to_png()` instead. SVG output can be embedded in PDF documents using external tools.

## See Also

- [How to Generate Barcodes with Aspose.BarCode FOSS](/barcode/python/how-to-work-with-barcode-generation-python/)
- [How to Configure Encode Options with Aspose.BarCode FOSS](/barcode/python/how-to-work-with-encode-options-python/)
- [Aspose.BarCode FOSS FAQ](/barcode/python/faq/)
- [Aspose.BarCode for Python — Enterprise Knowledge Base](https://kb.aspose.com/barcode/python/)