Scripts, Programs, and Plugins

Everything PlanetPDF does in its window can also be done without it: from a command prompt or script, by another program, or by a plugin that adds its own items to PlanetPDF's menus. This chapter explains what each is for and how to use it. It works the same on Windows, the Mac, and Linux.

Which one do I need?

Signing always asks you. Scripts, programs, and plugins may use every function, but whenever one wants to digitally sign a document with your Digital ID, PlanetPDF shows a window asking you first. A script can't answer it for you.

The command line

Where to run it

Running planetpdf with a file name instead of a command simply opens the file in the PlanetPDF window, as before.

Getting help

TypeTo see
planetpdf helpEvery command, by group, with a line on what it does.
planetpdf help exportOne command's options (here export).
planetpdf commands --jsonEvery command and option, for programs.
planetpdf --versionThe version of PlanetPDF.

Examples

planetpdf info report.pdf
Shows the pages, size, details, protection, signatures, and form fields.

planetpdf export report.pdf --format docx --out report.docx
Saves a Word copy.

planetpdf compress scan.pdf --quality small --out scan_small.pdf
Makes a smaller copy.

planetpdf redact report.pdf --preset ssn --find "John Q. Public" --overlay-text REDACTED --out report_redacted.pdf
Removes every Social Security number and the name for good, then checks the result.

planetpdf fill form.pdf --set "Name=Jane Doe" --set Agree=on --flatten --out filled.pdf
Fills in a form and makes the answers part of the page.

planetpdf sign contract.pdf --id <ID from signing-ids> --out contract_signed.pdf
Signs with a Digital ID from your certificate store; PlanetPDF asks you first.

In PowerShell, to compress every PDF in a folder:

Get-ChildItem *.pdf | ForEach-Object { planetpdf compress $_.FullName --out ($_.BaseName + "_small.pdf") }

How commands behave

CodeMeaning
0Done.
1It failed; the message says why.
2The command was used wrongly (unknown command, missing or bad option).
3Signing wasn't approved.
4Done, but a check failed (redaction verification, compliance check, or a signature that is invalid or was changed after signing).
130Stopped with Ctrl+C.

Passwords

For a protected file, or a Digital ID file's password:

Caution: a password typed straight on the command line (--password secret) can be seen by other programs on the computer. Use one of the two ways above.

Signing from the command line

planetpdf signing-ids lists the Digital IDs in Windows' certificate store (or the Mac Keychain) that can sign. Pass one with --id, or a Digital ID file with --pfx. Every time, PlanetPDF shows Allow Digital Signing? describing what will be signed; click Allow or Don't Allow. If it isn't allowed, the command ends with exit code 3.

Every command

Type planetpdf help and the command's name for its options.

GroupCommandWhat it does
ReadinfoDetails of a PDF: pages, size, metadata, protection, signatures, form fields
ReadtextThe text of a PDF's pages, in reading order
ReadsearchFind words, phrases, or patterns (SSNs, phone numbers…) in a PDF
ReadbookmarksA PDF's bookmarks
ReadcompareCompare the text of two PDFs
Readset-metadataChange a PDF's title, author, subject, or keywords
FormsfieldsA form's fields: names, kinds, values, and choices
FormsfillFill in a form's fields
Formsflatten-formsMake a form's fields part of the page
SignsignaturesCheck a PDF's digital signatures
Signsigning-idsThe Digital IDs in Windows' certificate store or the Mac Keychain that can sign
SignsignDigitally sign a PDF (always asks you first)
Standardscheck-complianceCheck a PDF against PDF/A, PDF/X, or PDF/E
Standardssave-as-standardSave as PDF/A, PDF/X, or PDF/E (through Ghostscript)
Optimizespace-usageWhat takes the room in a PDF (pictures, fonts, content…)
OptimizecompressMake a PDF smaller (pictures resampled, scans in black and white or gray, fonts cut down)
ExportexportSave a PDF's pages as Word, Excel, PowerPoint, pictures, text, HTML… (add --ai to read the pages with AI text reading, where it can run)
ScanocrRecognize text on scanned pages, so they can be searched and copied
Scanoptimize-scansStraighten, clean, and shrink scanned pages
Scanremove-blank-pagesRemove blank pages (scans' empty backs)
CreatecombineCombine PDFs and pictures into one PDF, in the order given
CreatecreateMake a PDF from each file (pictures, text, Office files, XPS, EPUB…)
Createweb-pageMake a PDF of a web page (through Microsoft Edge or Chrome)
PagessplitSplit a PDF into several files
PagesextractMake a new PDF of some pages
Pagesdelete-pagesDelete pages
PagesrotateTurn pages
PagesreorderPut the pages in a new order
PagesinsertInsert another PDF's pages
PagescropCrop pages (margins in points: 72 = 1 inch)
Pagesheader-footerAdd headers and footers ({page}, {pages}, {date}, {file})
PagesbatesAdd Bates numbers
PageswatermarkAdd a text or picture watermark
Pagesremove-marksRemove headers and footers, Bates numbers, watermarks, or backgrounds PlanetPDF added
RedactredactRemove text for good (words, phrases, patterns), then check the result
RedactsanitizeRemove hidden information: metadata, comments, attachments, scripts, hidden layers…
ProtectprotectPassword-protect a PDF (AES-256)
ProtectunprotectRemove a PDF's password protection

Two more commands are for programs: planetpdf commands lists the commands, and planetpdf serve runs the local API without a PlanetPDF window until you press Ctrl+C. For IT, planetpdf policy shows the settings an administrator made for everyone on the computer (see Checking that your policy is in force).

The local API (for programmers)

Other programs on your computer can ask PlanetPDF to do work through its local API: JSON-RPC 2.0, one JSON message per line, over a named pipe (Windows) or a socket file (Mac, Linux). Only programs running as you on this computer can connect; it is never open to the network. Every command of the command line is an API method of the same name, with the same options, and long jobs send progress as they go.

Programmers will find a ready-made Python client (planetpdf_client.py, standard library only) and an example plugin in the sdk folder of PlanetPDF's resources, and the full description (methods, messages, error codes) in the developer guide, docs/SCRIPTING.md.

The API is off until you turn it on: tick Let other programs and plugins use PlanetPDF in Preferences ▸ Scripting & Plugins (it takes effect the next time PlanetPDF starts; turning a plugin on starts it at once). The list of programs you allowed is sealed with a key Windows (or the Mac's Keychain) keeps for you, so a program can't add itself by editing the file: a list changed outside PlanetPDF is ignored, and each program is asked about again.

Plugins

A plugin is a small program that adds commands to PlanetPDF's menus. When you choose one of its items, PlanetPDF starts the plugin as a separate program, which then uses PlanetPDF through the local API, for example to stamp and file the open invoice.

Adding a plugin

  1. Choose Help ▸ Open Profile Folder and open the plugins folder (make it if it isn't there). On Windows this is %APPDATA%\Planet Networks\PlanetPDF\plugins.
  2. Copy the plugin's folder into it. (IT can also make plugins available to everyone from folders listed in the environment variable PLANETPDF_PLUGINS.)
  3. Turn it on, as below.

Turning a plugin on

Nothing a plugin contains runs until you turn it on.

  1. Choose Edit ▸ Preferences… and click Scripting & Plugins.
  2. Under Plugins, find it. The Asks to column says what it wants to do through PlanetPDF:
  3. Tick it. Turn On Plugin? shows its publisher, what it asks for, and the menu items it adds. Click Yes only if you trust where it came from.
  4. Its items appear at the end of the menus it names (File, Edit, View, Tools, Window, or Help) in every window.

To turn it off, untick it.

Changed plugins turn off. PlanetPDF remembers exactly what the plugin's files were when you turned it on. If any of them change (an update, or tampering), it is off again until you turn it on again, so you see what it asks for each time it changes.

What a plugin prints goes to logs\plugins in the profile folder, and what it did through PlanetPDF is in the Activity Log….

Important: a plugin is a program running as you, like any program you start. Its permissions limit what it can do through PlanetPDF (asking for anything else is refused), not what it could do on its own. Turn on only plugins from people you trust.