Code Snippets

Code Snippets

Practical examples of using Trusted Signatures CLI and API in real-world scenarios.

CLI Examples

Basic Signing

1
2
3
4
5
6
7
#!/bin/bash
export TS_API_KEY_ID="your_api_key_id"
export TS_API_KEY="your_api_key"

sign-pdf \
  --input document.pdf \
  --output signed-document.pdf

Batch Processing

1
2
3
4
5
6
7
8
9
#!/bin/bash
for pdf in input/*.pdf; do
  filename=$(basename "$pdf" .pdf)
  sign-pdf \
    --input "$pdf" \
    --output "signed/${filename}-signed.pdf" \
    --ltv \
    --limit-changes allow-forms
done

Invoice Workflow

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/bin/bash
# Generate and sign invoice
wkhtmltopdf invoice-template.html temp-invoice.pdf

sign-pdf \
  --input temp-invoice.pdf \
  --output "invoices/invoice-$(date +%Y%m%d-%H%M%S).pdf" \
  --ltv \
  --limit-changes no-changes

rm temp-invoice.pdf

CI/CD Pipeline

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
set -e

python generate_report.py --output temp-report.pdf

sign-pdf \
  --input temp-report.pdf \
  --output "reports/$(date +%Y-%m-%d)-compliance-report.pdf" \
  --ltv \
  --limit-changes allow-comments

aws s3 cp "reports/$(date +%Y-%m-%d)-compliance-report.pdf" \
  s3://company-reports/signed/

Docker Integration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Dockerfile
FROM alpine:latest
RUN apk add --no-cache curl
RUN curl -LO https://trusted-signatures.com/downloads/sign-pdf-v1.2.3-linux-amd64.tar.gz
RUN tar -xzf sign-pdf-v1.2.3-linux-amd64.tar.gz && mv sign-pdf /usr/local/bin/

# Usage
docker run -v $(pwd)/pdfs:/pdfs \
  -e TS_API_KEY_ID="your_api_key_id" \
  -e TS_API_KEY="your_api_key" \
  pdf-signer \
  --input /pdfs/document.pdf \
  --output /pdfs/signed-document.pdf \
  --ltv

Pipeline Integration

1
2
3
4
5
6
7
8
9
#!/bin/bash
export TS_API_KEY_ID="your_api_key_id"
export TS_API_KEY="your_api_key"

# Sign PDF using stdin/stdout pipes
cat input.pdf | sign-pdf --ltv > signed-output.pdf

# Or in a pipeline with other tools
wkhtmltopdf report.html - | sign-pdf --limit-changes no-changes > sealed-report.pdf

Common Patterns

  • Invoices: Use --limit-changes no-changes for tamper-proof documents
  • Forms: Use --limit-changes allow-forms for fillable PDFs
  • Reports: Use --ltv for long-term verification
  • Batch: Loop through directories for bulk processing