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
Notes
cdrFilter value (PDF, JPG, PNG and SVG each have one); pass None for options to take the defaults.Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initout = "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
FileName— full path including the extension. Forward slashes work on Windows.Filter— the format filter number, an integer, not a string like"jpg". That number is defined by the import/export filters installed on the machine, so it can differ between versions and between installations.Options— an export options object. Almost always passNoneand take the defaults.
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:
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:
- Returns False — the call was accepted but nothing was written. Usually a missing target folder, a full disk, or content the filter cannot handle. No exception is raised, so a bare try/except will not catch it.
- Raises
DISP_E_BADPARAMCOUNT(-2147352562,0x8002000E) — the argument count does not match the method prototype. Often a different overload, or theExportBitmapargument list passed toExportEx. - Raises
DISP_E_TYPEMISMATCH(-2147352571,0x80020005) — an argument has the wrong type. Classic cases: filter given as the string"JPEG", or a dict passed asOptions.
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
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
- Use it for batch previews, one image per page, lightweight files to send a client.
- Avoid it for print delivery (go through PDF), for anything needing tight colour profile control, and for vectors — think hard about fonts and effects before exporting SVG.
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.
- This section has 20 entries; this is one of them.
- See the full section index: Document
Other entries in this section
- doc.PagesThe page collection. doc.Pages.Count for the total, doc.Pages.Item(i)
- doc.AddPages(n)Appends n pages at the end. The idiom while len(doc.Pages) < page_inde
- doc.ActivePageThe current page object.
- doc.ActiveLayerThe active layer of the current page.
- doc.UnitDocument unit (cdrUnit). Every geometric value follows it: shape coord
- doc.ResolutionDocument resolution in dpi. Affects bitmap export and effect rendering
- doc.ReferencePointReference point for transforms. It anchors SetPosition and SetSize and
- doc.ClearSelection()Deselects everything. Call it before a batch run so you don't accident