Convert cmx to pdf

Contents
[ ]

Using Aspose.Imaging we can convert single paged or multi-page cmx image to pdf.

The following code snippet shows you how to convert cmx to pdf.

import aspose.pycore as aspycore
from aspose.imaging import Image, Color, TextRenderingHint, SmoothingMode
from aspose.imaging.imageoptions import PdfOptions, VectorRasterizationOptions
from aspose.imaging.fileformats.cmx import CmxImage
from aspose.imaging.fileformats.pdf import PdfDocumentInfo
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.cmx")), CmxImage) as image:
options = PdfOptions()
options.pdf_document_info = PdfDocumentInfo()
# Set rasterization options for fileformat
options.vector_rasterization_options = aspycore.as_of(
image.get_default_options([Color.white, image.width, image.height]),
VectorRasterizationOptions)
options.vector_rasterization_options.text_rendering_hint = TextRenderingHint.SINGLE_BIT_PER_PIXEL
options.vector_rasterization_options.smoothing_mode = SmoothingMode.NONE
image.save(os.path.join(data_dir, "result.pdf"), options)
if delete_output:
os.remove(os.path.join(data_dir, "result.pdf"))