Home/ Reference/ Document

doc.PublishToPDF(path)

Exports a PDF. The simplest export call there is; the defaults are fine.

Signature

doc.PublishToPDF(path)

Notes

Exports a PDF. The simplest export call there is; the defaults are fine.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
out = "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

Python
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:

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.

Python
# 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

Python
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

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.

Other entries in this section