Security

Encryption

gpdf supports AES-256 encryption (ISO 32000-2, Rev 6) with owner and user passwords.

Owner Password Only

The PDF can be opened without a password, but editing is restricted.

import (
    "github.com/gpdf-dev/gpdf"
    "github.com/gpdf-dev/gpdf/encrypt"
)

doc := gpdf.NewDocument(
    gpdf.WithPageSize(gpdf.A4),
    gpdf.WithEncryption(
        encrypt.WithOwnerPassword("owner-secret-123"),
    ),
)

User & Owner Passwords

The user password is required to open the PDF.

doc := gpdf.NewDocument(
    gpdf.WithPageSize(gpdf.A4),
    gpdf.WithEncryption(
        encrypt.WithOwnerPassword("owner-pass"),
        encrypt.WithUserPassword("user-pass"),
    ),
)

Permission Control

Restrict specific operations like printing, copying, or modifying.

doc := gpdf.NewDocument(
    gpdf.WithPageSize(gpdf.A4),
    gpdf.WithEncryption(
        encrypt.WithOwnerPassword("owner"),
        encrypt.WithUserPassword("user"),
        encrypt.WithPermissions(encrypt.PermPrint|encrypt.PermCopy|encrypt.PermPrintHighRes),
    ),
)

Available permissions:

ConstantDescription
encrypt.PermPrintAllow printing
encrypt.PermModifyAllow modification
encrypt.PermCopyAllow copying text
encrypt.PermAnnotateAllow annotations
encrypt.PermPrintHighResAllow high-resolution printing
encrypt.PermAllAll permissions (default)

PDF/A Conformance

Generate archival-quality PDFs that comply with PDF/A standards.

PDF/A-1b

import (
    "github.com/gpdf-dev/gpdf"
    "github.com/gpdf-dev/gpdf/pdfa"
)

doc := gpdf.NewDocument(
    gpdf.WithPageSize(gpdf.A4),
    gpdf.WithPDFA(), // defaults to PDF/A-1b
)

PDF/A-2b with Metadata

doc := gpdf.NewDocument(
    gpdf.WithPageSize(gpdf.A4),
    gpdf.WithPDFA(
        pdfa.WithLevel(pdfa.LevelA2b),
        pdfa.WithMetadata(pdfa.MetadataInfo{
            Title:      "Annual Report 2026",
            Author:     "ACME Corp",
            Subject:    "Financial Report",
            Creator:    "gpdf",
            CreateDate: "2026-01-15T10:30:00+09:00",
            ModifyDate: "2026-01-15T10:30:00+09:00",
        }),
    ),
)
LevelStandardDescription
pdfa.LevelA1bISO 19005-1PDF/A-1b (default)
pdfa.LevelA2bISO 19005-2PDF/A-2b

Digital Signatures

Sign PDFs with CMS/PKCS#7 digital signatures using RSA or ECDSA keys.

Basic Signing

import (
    "github.com/gpdf-dev/gpdf"
    "github.com/gpdf-dev/gpdf/signature"
)

// Generate the PDF first
data, _ := doc.Generate()

// Sign it
signed, err := gpdf.SignDocument(data, signature.Signer{
    Certificate: cert,
    PrivateKey:  key,
},
    signature.WithReason("Approved"),
    signature.WithLocation("Tokyo"),
)

With Certificate Chain and Timestamping

signed, err := gpdf.SignDocument(data, signature.Signer{
    Certificate: cert,
    PrivateKey:  key,
    Chain:       []*x509.Certificate{intermediateCert},
},
    signature.WithReason("Contract signed"),
    signature.WithLocation("New York"),
    signature.WithTimestamp("http://tsa.example.com"),
)
OptionDescription
signature.WithReason(reason)Reason for signing
signature.WithLocation(location)Location of signing
signature.WithTimestamp(tsaURL)RFC 3161 timestamp authority URL
signature.WithSignTime(t)Explicit signing time (default: now)