Manipulating FODG files
Contents
[
Hide
]
Load of FODG file
Aspose.Imaging supports load of FODG file format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pycore as aspycore | |
from aspose.imaging import Image, SizeF | |
from aspose.imaging.imageoptions import OdgRasterizationOptions, PngOptions | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
data_dir = templates_folder | |
with Image.load(os.path.join(data_dir, "template.odg")) as image: | |
rasterization_options = OdgRasterizationOptions() | |
rasterization_options.page_size = aspycore.cast(SizeF, image.size) | |
options = PngOptions() | |
options.vector_rasterization_options = rasterization_options | |
image.save(os.path.join(data_dir, "result.png"), options) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.png")) |
Improve default font option usage on Linux
As Aspose.Imaging supports default font setting, it needs to be enhanced to work on Linux too. The example below shows how to use default font option on Linux.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.imaging import Image, FontSettings | |
from aspose.imaging.imageoptions import PngOptions, OdgRasterizationOptions | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
data_dir = templates_folder | |
def export_to_png(file_path, default_font_name, outfile_name): | |
FontSettings.set_default_font_name(default_font_name) | |
with Image.load(file_path) as document: | |
save_options = PngOptions() | |
save_options.vector_rasterization_options = OdgRasterizationOptions() | |
save_options.vector_rasterization_options.page_width = 1000.0 | |
save_options.vector_rasterization_options.page_height = 1000.0 | |
document.save(outfile_name, save_options) | |
# Run | |
FontSettings.set_fonts_folder(os.path.join(data_dir, "fonts")) | |
FontSettings.set_get_system_alternative_font(False) | |
export_to_png(os.path.join(data_dir, "template.odg"), "Arial", os.path.join(data_dir, "result.png")) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.png")) |