Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

How-to

How to automate layout exports from the command line

Run ZawebaLayout.exe with --export or --run to batch export PDFs, pictures, EPUB and more from Layout by Zaweba with no window, ideal for scripts and schedules.

How to automate layout exports from the command line

Exports can run from the command line with no window at all. Run ZawebaLayout.exe with --export, give it a file or a whole folder and a --format such as pdf, and Layout by Zaweba writes the results. For more involved jobs, --run takes a file of requests in JSON and can write the results to another file. Both make it easy to script repeat exports or run them on a schedule.

If you only export one document a week, the File menu is fine. The command line pays off when the same exports happen again and again: a folder of catalogue pages to turn into PDFs each night, or a set of documents that need PNG previews for a website every time they change.

The export command

The --export option takes a file or a folder. Add --format with one of pdf, png, jpeg, tiff, svg, epub, html, text, rtf or package. Optional switches refine it: --out says where to write, --preset picks an export preset (a press PDF preset rather than the default, for example), and --subfolders works through folders inside the one you named.

A typical line exports every document in a folder to PDF with a chosen preset, writing into an output folder. Another might produce PNG previews of the same documents for a web page. Because package is a format too, you can gather documents with their pictures and fonts for the printer without opening each one.

Running requests with --run

Every command in Layout can be run by an id with JSON arguments and returns a JSON result, and each one is a single undo step when used inside the app. The command line exposes the same thing: --run requests.json reads a list of requests, carries them out, and --out results.json writes what happened.

The commands cover the document, pages and frames. There's commands.list to see what's available, pages.list and page.add for pages, frames.list and frame.get, frame.add, frame.set and frame.delete for frames, text.get and text.set for words, and selection.get and selection.set. With those you can, for instance, open a template, set the text of a named frame to this week's headline, and export, all from a script.

Building a routine that runs itself

Start small. Get one --export line working for one document, check the output, then widen it to a folder. Put the command in a batch file or script so it's the same every time, and use Windows Task Scheduler if it should run overnight.

Keep templates tidy if you plan to change text through --run. Frames that a script fills should be easy to identify, and styles should already be applied so the new text picks up the right look.

Check the results file. When something goes wrong, the answer is usually in the result for that request rather than in the exported file.

Output jobs inside the app

If you'd rather stay in the app, File > Output jobs holds named sets of exports with naming patterns. One click runs the set. Output jobs stop when pictures or fonts are missing, which is exactly what you want before a file goes to a printer. Many people set up an output job in the app first, then move to the command line when the routine is settled.

Mistakes to avoid

Don't let an unattended export overwrite something important. Point --out at a dedicated folder. Remember that a script will happily export a document with overset text or a low resolution picture; open a sample now and then and look at the preflight panel, or rely on output jobs, which stop on missing pictures and fonts.

Layout by Zaweba works offline, so these scripts run on your own machine with no account and no cloud service in the middle.