Export Pages as PDFs?

How can I export files through my plugin? When I check the App.ActiveDocument module, I see PdfExportPreferences, but no export function. I’d like to export as pdf in code(want to avoid dialog appering).

So while there are both PDFExportPreferences and Adobe PDF Presets, the export is a method of the document (and maybe other elements)

I believe it is either

But that requires you to have the ExportFormat enumeration

I’ve not tried either in UXP yet, however.

Perfect okay, hey where does the ExportFormat.PDF_TYPE come from, it’s undefined when I try to call it in UDT.

the ExportFormat is an enumeration. When you see InDesign values starting with a capital letter, it’s likely an Enumeration - especially when the part after the . is in ALL_CAPS. And they have to be added to your UXP code. Perhaps there is an easier way, but I’m using something like this:

var { ExportFormat } = require {'indesign'};

there’s a boatload of them! My current list is:

var {
	} = require(appName_s);

where appName_s is ‘indesign’


Crystal Clear, okay I’ll try it out

If anyone was looking for a plug-and-play solution to export a PDF of your currently open document, here you go:

let ID = require("indesign");
const exportPath = "/Users/username/Desktop/test.pdf"; // Change this to where you want the file to be exported

// if you just want the PDF exported with the most recent export preset, use this
app.activeDocument.exportFile(ID.ExportFormat.PDF_TYPE, exportPath);

// if you want the file exported with a specific pdf export preset, use this:
const presetName = "[High Quality Print]"; // Change this to whichever PDF Export preset you want to use
const pdfExportPreset = app.pdfExportPresets.itemByName(presetName);
app.activeDocument.exportFile(ID.ExportFormat.PDF_TYPE, exportPath, false, pdfExportPreset);

As an addendum, you can get a list of all the PDF preset names in your application with:


This code should all work from the debug console assuming you have a document open.

Dynamite, thanks a million