Convert CDR to PDF in Python
Contents
[
Hide
]
Using Python Image Processing Library Aspose.Imaging, we can convert single or multipage CDR file to PDF.
The following code snippet shows you how to convert CDR to Pdf.
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 VectorMultipageImage, Image, SizeF | |
from aspose.imaging.imageoptions import CdrRasterizationOptions, MultiPageOptions, PdfOptions | |
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 aspycore.as_of(Image.load(os.path.join(data_dir, "template.cdr")), VectorMultipageImage) as image: | |
# Create page rasterization options | |
page_options = [] | |
for page in image.pages: | |
option = CdrRasterizationOptions() | |
option.page_size = aspycore.cast(SizeF, page.size) | |
page_options.append(option) | |
# Create PDF options | |
multi_page_options = MultiPageOptions() | |
multi_page_options.page_rasterization_options = page_options | |
options = PdfOptions() | |
options.multi_page_options = multi_page_options | |
# Export image to PDF format | |
image.save(os.path.join(data_dir, "result.pdf"), options) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.pdf")) |