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
Notes
Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initout = "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
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
)
- Width / Height are pixels. Not millimetres, not document
units. This is the classic mistake: passing
210for 210mm and getting a 210px image. - ResolutionX / ResolutionY are dpi, written into the file metadata. They decide how large the image "claims to be" in a layout application. 300 for print, 72 or 96 for screen.
- AntiAliasType is an enum. Which of 1, 2, 3 means none / normal / enhanced is
not consistent across versions, so do not copy it from someone else. Export once with
1and once with2, zoom into an edge, and keep the one without stair-stepping. - Dithered only matters when the output palette is limited, such as 256 colours. On a true-colour export it makes no difference whatever you pass.
- Transparent only has an effect on formats with an alpha channel. JPEG has
none, so passing
Truewill not give you a transparent background — which is why people report "I set it and nothing happened". - CropToPage with
Trueexports the page area only;Falsedrags in whatever sits outside it. For e-commerce images, it is almost alwaysTrue.
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:
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.
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
- "300dpi means print quality" — it does not. dpi only describes pixel density. Whether it can be printed depends on the content: a 72dpi bitmap exported as a 300dpi PNG has been interpolated, and detail does not appear out of nowhere. Check the source bitmap separately, see bitmap information.
- "Exporting changes the document resolution" — no. Bitmap objects in the document are untouched; only the output file changes.
- "True means it worked" — same as
ExportEx. True means the call was accepted. Checking the file size is not optional.
How it divides the work with Resample and ConvertToBitmap
ExportBitmap— writes a file, document unchanged. For delivering images.Resample— rewrites the bitmap object itself, irreversibly. For genuinely resampling artwork.ConvertToBitmap— rasterises vectors or text into a bitmap object, irreversibly. For cases that need to behave like a bitmap.
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.
- 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