Created
June 21, 2025 08:06
-
-
Save documentprocessing/97c8a6114f09e0223611ea81e4bcd687 to your computer and use it in GitHub Desktop.
Custom Template Processing with Pandoc API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.github.davidmoten.pandoc.Pandoc; | |
| import java.nio.file.*; | |
| import java.util.*; | |
| /** | |
| * Generates legal contracts using custom Pandoc templates with dynamic variables. | |
| * Features: | |
| * - YAML front-matter injection for client-specific terms | |
| * - Conditional clauses via Pandoc filters | |
| * - Multi-format output (PDF for signing, DOCX for editing) | |
| * - Digital signature placeholder integration | |
| */ | |
| public class ContractGenerator { | |
| public static void main(String[] args) throws Exception { | |
| // 1. Initialize Pandoc with legal-doc defaults | |
| Pandoc pandoc = Pandoc.create() | |
| .option("--fail-if-warnings"); // Strict mode for legal docs | |
| // 2. Template variables (e.g., from CRM system) | |
| Map<String, String> variables = new HashMap<>(); | |
| variables.put("client_name", "Acme Corp"); | |
| variables.put("effective_date", "2025-01-20"); | |
| variables.put("jurisdiction", "EU"); // Triggers GDPR clauses in template | |
| // 3. Path configurations | |
| Path markdownTemplate = Paths.get("templates/master_contract.md"); | |
| Path latexTemplate = Paths.get("templates/legal_template.tex"); | |
| Path outputDir = Paths.get("output/contracts"); | |
| Files.createDirectories(outputDir); | |
| // 4. Generate contract with dynamic variables | |
| pandoc.from("markdown") | |
| .to("pdf", "docx") // Dual output | |
| .option("--template=" + latexTemplate.toString()) | |
| .option("--include-in-header=clauses/gdpr.tex") // Conditional GDPR terms | |
| .filter("pandoc-mustache") // Handle {{variable}} substitution | |
| .variables(variables) | |
| .standalone() | |
| .execute( | |
| Files.newInputStream(markdownTemplate), | |
| Files.newOutputStream(outputDir.resolve("contract_" + variables.get("client_name") + ".pdf")), | |
| Files.newOutputStream(outputDir.resolve("contract_" + variables.get("client_name") + ".docx")) | |
| ); | |
| System.out.println("Generated contracts for " + variables.get("client_name")); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment