Home/ Reference/ Document

doc.ExportEx(path, filter, options)

General-purpose export. filter takes a cdrFilter value (PDF, JPG, PNG and SVG each have one); pass None for options to take the defaults.

Signature

doc.ExportEx(path, filter, options)

Notes

General-purpose export. filter takes a cdrFilter value (PDF, JPG, PNG and SVG each have one); pass None for options to take the defaults.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
out = "D:/output/final.pdf"

# arguments: file path / format filter / export options
# filter numbers vary a lot; if it fails, use PublishToPDF instead
try:
    doc.ExportEx(out, 0, None)
    print("Exported: ", out)
except Exception as e:
    print("ExportEx failed, switching to the PDF call: ", e)
    doc.PublishToPDF(out)

It writes a file, not the document

Keep this separate from SaveAs and a lot of confusion disappears. ExportEx renders the current document into an external file (JPEG, PNG, TIFF, PDF, SVG and so on). The document itself is untouched: doc.FileName does not change, and doc.Dirty does not become False. It is not a save. Unsaved edits are still only in memory after an export.

The three arguments

Why you should not copy filter numbers from the internet

The widely copied "filter table" often fails, and sometimes exports a completely different format than intended. The reason is concrete: the mapping between numbers and formats is not part of any public CorelDRAW specification, it is the order in which filters were registered at install time. Install several versions, or add extra import/export plug-ins, and the numbers can shift.

The reliable approach is to confirm on the machine in front of you, then write that number down. Probe once:

Python
import os

def probe_filter(doc, filt, out_dir="D:/output"):
    # try one filter number, keep the file only if it really was produced
    out = os.path.join(out_dir, f"probe_{filt}.png")
    try:
        ok = doc.ExportEx(out, filt, None)
    except Exception as e:
        return filt, "raise", repr(e)
    made = os.path.exists(out) and os.path.getsize(out) > 0
    return filt, bool(ok), made

Walk the candidate numbers upward and keep the one that actually produces a file you can open. A True return does not prove the file is usable — that gets its own section below.

A return value and an exception are different failures

ExportEx returns a Boolean, and there are three distinct ways it can fail:

The broader DISP_E_EXCEPTION (-2147352567, 0x80020009) generally means the callee failed internally. e.args[2] usually carries a more specific description; printing it beats guessing.

Create the folder yourself; overwriting is silent

Export does not create directories for you. A missing folder usually ends as False or an exception rather than as a helpful new directory. The reverse is also true: an existing file at the target path is overwritten without a prompt. Check the folder before a batch run, and put a sequence number or timestamp in the name — that is cheaper than recovering files later.

The version that keeps working

If all you need is "a usable image" and the filter numbers keep misbehaving on someone else's machine, change route: call PublishToPDF first, then convert that PDF to a bitmap with an external tool. The PDF export path is far more stable and takes fewer arguments; the bitmap step then happens outside anything that depends on the CorelDRAW version. The cost is one extra step and one extra dependency. The benefit is that it almost never breaks when the machine changes.

Complete example: check the return value, handle the folder

Python
import os, time

def export_image(doc, path, filt):
    folder = os.path.dirname(path)
    if folder and not os.path.isdir(folder):
        os.makedirs(folder)              # export never creates it for you

    ok = doc.ExportEx(path, filt, None)   # Options=None means defaults
    time.sleep(0.2)                       # let the file handle close before checking

    if not ok or not os.path.exists(path) or os.path.getsize(path) == 0:
        raise RuntimeError(f"export produced nothing: {path} (filter {filt})")
    return path

print(export_image(doc, "D:/output/page1.png", 1))

Note the time.sleep(0.2). The write lands asynchronously, so reading the size immediately occasionally reports 0. That is not a failed export, just a file that is not finished yet.

When to use it, and when not to

The closer a job gets to print delivery, the less you want a bitmap export call. Bitmap export is for screens and previews.

About this section: Document

Document — documents and file handling.

Other entries in this section