When working with 2D animation in Blender, we may need to export objects created with the Grease Pencil tool to external formats such as SVG or PDF.
Using the UI, we can export Grease Pencil objects to PDF or SVG formats by selecting in the main menu, respectively:
- File – Export – Grease Pencil as SVG
- File – Export – Grease Pencil as PDF
If we need to export Grease Pencil to these formats using the Blender Python API, we can use the gpencil_export_ operators.
For saving to .svg:
1 |
bpy.ops.wm.gpencil_export_svg(filepath='//suzanne.svg') |
and to .pdf:
1 |
bpy.ops.wm.gpencil_export_pdf(filepath='//suzanne.pdf') |
In both operators, we need to specify the path to the file in which the Grease Pencil objects will be saved in the “filepath” parameter.