Home/ Reference/ Document

doc.ExportBitmap(...)

Bitmap export. The signature is long (width, height, dpi, antialiasing, transparency, color profile, whether to crop to page). Export a PDF first, or just use Export

Signature

doc.ExportBitmap(...)

Notes

Bitmap export. The signature is long (width, height, dpi, antialiasing, transparency, color profile, whether to crop to page). Export a PDF first, or just use ExportEx, and save yourself the trouble.

Python example (runnable)

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

# long argument list, roughly in this order:
# path, filter, width(px), height(px), X dpi, Y dpi, antialias, dither, transparent, profile, crop-to-page
doc.ExportBitmap(out, 0, 2000, 1414, 300, 300, 2, 1, 0, 1, 1)
print("Bitmap exported: ", out)

# if it complains about arguments, fall back to the safe form:
# doc.ExportEx(out, 0, None)

What it adds over ExportEx: you set the pixel size

ExportEx lets CorelDRAW work out the output size by its own rules and you accept the result. ExportBitmap hands you the controls: how many pixels the target file gets and what dpi it is tagged with are both arguments. A 800x800 e-commerce hero, a 1000x1000 variant, "long edge 1200" — this is the call for that. It still does not modify the document. What it changes is the pixel count of the file, not the resolution of the artwork. Keep it clearly separate from Resample, which really does rewrite the bitmap object.

Eleven arguments, one at a time

Python
ok = doc.ExportBitmap(
    "D:/output/hero.png",   # 1  FileName
    1,                      # 2  Filter (number, not a string)
    800,                    # 3  Width  in pixels
    800,                    # 4  Height in pixels
    300,                    # 5  ResolutionX (dpi)
    300,                    # 6  ResolutionY (dpi)
    aa,                     # 7  AntiAliasType  - value varies, see below
    False,                  # 8  Dithered        - only matters for indexed colour
    False,                  # 9  Transparent     - only for PNG / GIF / TIFF
    True,                   # 10 UseColorProfile
    True,                   # 11 CropToPage      - export the page, not the whole workspace
)

When Width/Height and Resolution disagree

The two groups describe the same thing: pixel size = physical size x dpi. Give CorelDRAW both and it has to pick one as authoritative. Both behaviours have been observed in the wild. Some builds honour Width/Height and merely record the dpi in metadata; others derive the pixels from the dpi and overwrite your Width/Height.

Do not guess — verify from the output. Read the real pixel size after exporting and adjust if it does not match:

Python
from PIL import Image      # pip install pillow

im = Image.open("D:/output/hero.png")
print(im.size, im.info.get("dpi"))

That answers both questions at once: what the pixel count actually is, and whether the dpi got written. Ten seconds here beats shipping a "the size is occasionally wrong" bug.

Complete example: export at a target dpi, compute the pixels yourself

The lowest-friction approach is to trust only one set of numbers: multiply page size by dpi to get pixels, then pass a self-consistent set of values for both Width/Height and Resolution, leaving the engine nothing to guess at.

Python
import os, time

def export_at_dpi(doc, path, filt, dpi=300, aa=2, transparent=False):
    page = doc.ActivePage
    # page size is in document units, so convert to inches first
    w_in = page.SizeWidth  / 25.4        # this line assumes millimetres
    h_in = page.SizeHeight / 25.4

    w = max(1, int(round(w_in * dpi)))
    h = max(1, int(round(h_in * dpi)))

    folder = os.path.dirname(path)
    if folder and not os.path.isdir(folder):
        os.makedirs(folder)

    ok = doc.ExportBitmap(path, filt, w, h, dpi, dpi, aa,
                          False, transparent, True, True)
    time.sleep(0.2)
    if not ok or not os.path.exists(path) or os.path.getsize(path) == 0:
        raise RuntimeError(f"ExportBitmap failed: {path}")
    return path

print(export_at_dpi(doc, "D:/output/hero.png", 1, dpi=300))

The unit conversion above is deliberately spelled out to make one point clear: normalise to inches first, then multiply by dpi. In production code the easier route is to switch the document to millimetres once (doc.Unit = 4 on most builds, and always read it back afterwards), after which every size is already in millimetres.

Three common misreadings

How it divides the work with Resample and ConvertToBitmap

Of the three, only the first is a safe default. The other two change the document, so save first.

About this section: Document

Document — documents and file handling.

Other entries in this section