https://github.com/bojarlab/glycorender
Bespoke renderer for GlycoDraw .svg into .pdf/.png
https://github.com/bojarlab/glycorender
glycans glycoinformatics pdf renderer svg
Last synced: 2 months ago
JSON representation
Bespoke renderer for GlycoDraw .svg into .pdf/.png
- Host: GitHub
- URL: https://github.com/bojarlab/glycorender
- Owner: BojarLab
- License: mit
- Created: 2025-03-24T15:18:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-02-05T14:07:01.000Z (4 months ago)
- Last Synced: 2026-02-05T22:45:16.273Z (4 months ago)
- Topics: glycans, glycoinformatics, pdf, renderer, svg
- Language: Python
- Homepage:
- Size: 363 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# glycorender
A bespoke SVG to PDF/PNG renderer for the GlycoDraw platform, specialized in accurately rendering glycan structures with support for chemical notations and path-based text positioning.
[](https://pypi.org/project/glycorender/)
[](https://pypi.org/project/glycorender/)
[](LICENSE)
## Features
- Accurate SVG to PDF and PNG conversion for glycan structures
- Support for text on paths with proper positioning and orientation
- Special handling for monosaccharide properties like "Df" with proper styling
- Gradient fills for circles and shapes
- Precise connection path rendering between glycan elements
- Support for various SVG path commands
## Installation
```bash
pip install glycorender
```
## Quick Start
```python
from glycorender import convert_svg_to_pdf, convert_svg_to_png
# Convert SVG file to PDF
with open('glycan_structure.svg', 'r') as f:
svg_data = f.read()
convert_svg_to_pdf(svg_data, 'output.pdf')
# Convert SVG file to PNG
convert_svg_to_png(svg_data, 'output.png')
# Or directly from SVG data
svg_data = """..."""
convert_svg_to_pdf(svg_data, 'output.pdf')
convert_svg_to_png(svg_data, 'output.png')
```
## Use Cases
GlycoRender is specifically designed for:
- Converting glycan structure diagrams from GlycoDraw to publication-quality PDFs or PNGs
- Preserving the exact layout and styling of complex carbohydrate representations
- Ensuring chemical notations are properly formatted in the output
- Maintaining the correct connections between monosaccharide units
## API Reference
### `convert_svg_to_pdf(svg_data, pdf_file_path)`
Converts SVG data to a PDF file.
Parameters:
- `svg_data` (str or bytes): SVG content either as a string or bytes
- `pdf_file_path` (str): Path where the output PDF should be saved
### `convert_svg_to_png(svg_data, png_file_path)`
Converts SVG data to a PNG file.
Parameters:
- `svg_data` (str or bytes): SVG content either as a string or bytes
- `png_file_path` (str): Path where the output PNG should be saved
## Supported SVG Elements
- ``: Full support for path commands (M, L, H, V, Z, etc.)
- ``: Support for basic circles and gradient-filled circles
- ``: Support for rectangles with stroke and fill
- `` and ``: Support for text placement along paths with proper orientation
- ``: Support for path and gradient definitions
- ``: Support for radial gradients with stops
## Dependencies
- ReportLab: For PDF generation
- PyMuPDF: For PNG conversion
- Pillow: For PNG metadata injection
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.