doc.PublishToPDF(path)
Exports a PDF. The simplest export call there is; the defaults are fine.
Signature
Notes
Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initout = "D:/output/final.pdf"
doc.PublishToPDF(out) # one argument is enough, the rest default
print("PDF written: ", out)
The default exit for print delivery
Of every export route in CorelDRAW, PublishToPDF takes the fewest arguments, varies
the least between versions, and is the one a print shop is most likely to accept without argument.
It has a single required parameter (the target path) and takes no filter number, which sidesteps the
whole drifting-number problem that ExportEx has. If the goal of your script is "hand
this artwork to somebody who will print it", this is the route with the highest success rate.
Signature and return value
ok = doc.PublishToPDF("D:/output/final.pdf") # returns a Boolean
It returns a Boolean, and like ExportEx it can return False without raising. A bare
try/except is not enough; you must also check that the file was really written. It
does not modify the document: doc.FileName and
doc.Dirty are both unaffected.
The PDF options are not arguments of this method
This is where most people get stuck. Compression, image downsampling, font embedding, whether bleed and crop marks are included — none of it is passed as method arguments. It all comes from the document's publish settings, which is exactly what you see in the "Publish to PDF" dialog in the CorelDRAW UI.
That leads to a consequence worth internalising: the same script can produce different PDFs on different machines, because the settings travel with the file or with whatever was used last. To make output reproducible, set the options in CorelDRAW and ship them with the template, rather than expecting code to specify them. This is the opposite of the "just pass the right argument" instinct.
Font embedding: check this before delivery
If a font is not embedded, the reader substitutes it and the layout moves — leading, glyph width, line breaks, all of it. And because a PDF does not look wrong at a glance, this survives until the print shop calls you. Publish settings usually include an embedding option; verify it in under a minute:
- Open "Document properties → Fonts" in any PDF reader and look for your font in the list. An empty list, or a substitute listed instead, means it is not embedded.
- The command line tool
pdffonts yourfile.pdflists every font with anembcolumn. Onlyyescounts.
CJK fonts are large, and embedding them can balloon the file, so some presets skip CJK fonts on purpose to keep the size down. That is the single most common reason Chinese or Japanese layouts collapse on someone else's machine.
Bleed and crop marks are not controlled from code
Bleed is a page property, defined in page setup. Crop marks are a toggle in the publish settings. All a script can do is set the bleed correctly, then publish. "Padding the bleed to 3mm" means changing page size or object positions — that is not the PDF export's job.
# bleed is a document property, set it before publishing, not during
doc.ActivePage.BleedWidth = 3 / 25.4 # 3mm, if the document unit is inch
doc.ActivePage.BleedHeight = 3 / 25.4
The value follows the document unit, which is why 3 / 25.4 is necessary in an inch
document. Switch the document to millimetres and you can write 3 directly — but changing
the unit affects every unit-based property in the document. See
doc.Unit.
Complete example
import os, time
def publish_pdf(doc, path):
folder = os.path.dirname(path)
if folder and not os.path.isdir(folder):
os.makedirs(folder) # it will not create the folder
if os.path.exists(path):
os.remove(path) # so we can tell a stale file from a fresh one
ok = doc.PublishToPDF(path)
time.sleep(0.3) # the write is not synchronous
if not ok:
raise RuntimeError(f"PublishToPDF returned False: {path}")
if not os.path.exists(path) or os.path.getsize(path) == 0:
raise RuntimeError(f"PDF missing or empty: {path}")
return path
print(publish_pdf(doc, "D:/output/final.pdf"))
Deleting the old file first is a small trick worth knowing. If the export fails silently, the previous file is still there, so an "exists" check reports success. Delete first, then check, and the distinction between "written now" and "left over from last time" becomes visible.
Notes for batch publishing
- Do not put it in a tight loop. Each publish writes to disk and builds font subsets, which is far slower than drawing shapes. For a document of dozens of pages, publishing once beats publishing page by page.
- Sleep between iterations —
time.sleep(0.2)or more. CorelDRAW is a single-threaded COM server and back-to-back heavy work can leave it apparently hung, with calls that never return. See throttling. - Make it retryable. PDF publishing fails intermittently, and a reader holding the target file open is a common cause. Two or three retries with a delay beats aborting the whole batch.
When to use it
Print delivery, final files for a client, anything that must keep vectors and selectable text. In
the other direction, when you need exact pixel dimensions for an e-commerce backend, a bitmap export
is more direct. The role of PublishToPDF is clear: finished goods, not working
material.
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