Support for command line compilation and custom command execution for PDFs

Many users have specific needs around the post-processing of generated PDF manuscripts, such as adding watermarks, compressing files, or applying other treatments. Currently, I use command-line tools to modify PDFs of my manuscripts after compilation in Scrivener (e.g., using a script to add a watermark).

Given that many third-party tools effectively handle features that may be missing in Scrivener, I propose a new feature: the ability to specify a custom command to be executed automatically after a project is compiled, referencing the generated file. For example:

command.sh %file
command.ps1 %file
command.bat %file

This would allow advanced users to integrate external tools like PDF Toolkit directly into their Scrivener workflow, streamlining tasks such as adding watermarks, compressing PDFs, and more.

Additional Suggestion:

Cherry on top would be to allow users to save multiple custom commands within in the general Scrivener settings. This would enable users to select which command to execute based on the selected compilation format (e.g., choosing different scripts for different output formats like PDF, DOCX, etc.).

This feature would provide flexibility for advanced users, enhance Scrivener’s utility, and leverage the power of existing third-party tools – Thus offloading a lot of feature request to integration wth 3rd party utilities.

You mean… like “24.22 Processing” in the Scrivener manual?

Using the post-processing capability, you can have Scrivener send the compiled source document to any utility capable of accepting data and arguments from the command-line shell, including your own scripts.

2 Likes

You mean… like “24.22 Processing” in the Scrivener manual?

No. Because section 24.22 clearly says that:

Available to the “MultiMarkdown” and “Plain Text” compile file types…

And I was referring to PDF files. I changed the title of the post to make it clearer.

Oh, I see. That would indeed be convenient. I haven’t used Scrivener to generate the PDF output in a while, so it wasn’t obvious how you’re approaching it.

1 Like

I should’ve been clearer. Also since we’re in the subject. If there was a command line from scrivener that would actually compile a project without the needing of opening Scrivener, than it would be even more powerful. This is because we could then pipe the resulting file into another command line tool.

scrivener-compile --project MyNovel.scriv --output pdf --format 'Manuscript (times)' --filename MyNovel.pdf | some-pdf-cli-tool MyNovel.pdf ...

That would be a spowerful as it gets!

But if you didn’t modify the project’s content (in Scrivener), why would you need to compile it (again)? :thinking: You know what I mean…

Either Scrivener is already open (because you edited something), and then you can already simply compile or initiate an elaborate post-processing chain right from the Compiler, including PDF generation in the Terminal. Or not. In that case you likely still possess the last compiled (or “raw”) output and there’s not need to involve Scrivener. Maybe I’m overthinking this.

1 Like

+1 for post-processing for all outputs, there are many use cases to improve workflow not only for PDF but other outputs too…

As a small side-note, many use cases for markdown or plain text do generate PDFs (the text is an intermediate, for example Scrivener’s LaTeX template uses plain text but generates PDF output), so technically Scrivener’s post-processing can automate PDF customisation. But you need to switch to use text as an intermediate + PDF engine for that workflow enhancement to apply.

As as stopgap, you can use file or folder watcher scripts to trigger post-processing. On macOS this is built-in using launchd, there are several 3rd party commandline tools, and I’m sure on Windows there are solutions too.

3 Likes

But if you didn’t modify the project’s content (in Scrivener), why would you need to compile it (again)? :thinking: […]

Say that I have a few beta readers for example, and I want to add watermarks for all of them. Some will also follow a different format (proof copy vs manuscript). I could have a script that would produce multiple copies with different watermarks. :slight_smile:

While I do believe that Scrivener could benefit from built-in watermark feature for PDFs (it has been asked here before), I can see how this specific requirement is an over-stretch. So off-loading to 3rd party tools would be the way to go. With a CLI tool from Scrivener, it would be the cherry on steroids at the top of the cake! :exploding_head:

Oh, I get that part. I just fail to see what Compiling via command-line parameters would change (since Scrivener doesn’t watermark, but also in general). :thinking:

But yeah, I won’t argue against a post-processing setting for all formats.

Ok so picture this: I want to create 20 PDF outputs. Each one of them should have the name of the beta reader plastered as a watermark on each page. Some of these are formated in manuscript modern. Some in manuscript courier. some are final proof.

How would you do that today with Scrivener and how long would it take?

With the example I gave, that could be done in seconds, not minutes.

I could have a text file that contains the names of beta readers. A shell script would parse this file and execute the scrivener-compile executable for each case, then piping the output file to a 3rd party pdf tool.

Now picture all sorts of complex user requirements that Scrivener just managed to enable by offloading it to third party tools with this feature.

You could also “hijack” the open with dropdown menu, but it’s not a fun endeavor (registering a user script as a valid “PDF app”).

1 Like

About zero seconds. I wouldn’t do it in Scrivener. :see_no_evil:

Okay, to be fair, I would still compile it once to MMD, that’s not zero. But you can automate everything else, the PDF generation, the watermarking, which users gets what format, and possibly even email it to them. Of course you have to set this up once. But you have to do that anyways.

(Basically the other way round, not launching Scrivener 20 times, but Scrivener launches your script once and that does whatever based on your user “database”.)

Ok. So I need to look into MMD then. Haven’t used it. I’m curious to read more about Scrivener support for markdown (reading this) as well as @nontroppo’s pandoc documentation.

1 Like

Almost anything that you might want to do will be done more easily before generating the PDF than after. The PDF format, by design, is notoriously difficult to edit.

1 Like

Just to quick summarise, most of us don’t use markdown directly when writing, but use Styles and Section Types that are a core part of Scrivener’s writing environment. The magic happens in the compiler, where Scrivener translates these Scrivener features to text markup, then the post-processor does its magic to do whatever you want. You are not limited to PDFs either, keeping output flexible. It can be a bit overwhelming when trying to come up with a workflow…

For PDF output you have a large number of engines available: Pandoc - Pandoc User’s Guide — the standard is LaTeX, but my current crush is Typst (accepting this is still a young project at V0.11 and will change as features stabilise), and if I wrote fiction I would also contemplate PrinceXML.

2 Likes

Or WeasyPrint (saving about $495, a.k.a. free and open source).

2 Likes