セキュリティ

暗号化

gpdfはオーナーパスワードとユーザーパスワードによるAES-256暗号化(ISO 32000-2、Rev 6)をサポートしています。

オーナーパスワードのみ

パスワードなしでPDFを開くことができますが、編集は制限されます。

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"),
    ),
)

ユーザーパスワードとオーナーパスワード

PDFを開くにはユーザーパスワードが必要です。

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

権限制御

印刷、コピー、変更などの特定の操作を制限します。

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

利用可能な権限:

ConstantDescription
encrypt.PermPrint印刷を許可
encrypt.PermModify変更を許可
encrypt.PermCopyテキストのコピーを許可
encrypt.PermAnnotate注釈を許可
encrypt.PermPrintHighRes高解像度印刷を許可
encrypt.PermAllすべての権限(デフォルト)

PDF/A準拠

PDF/A標準に準拠したアーカイブ品質のPDFを生成します。

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

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(デフォルト)
pdfa.LevelA2bISO 19005-2PDF/A-2b

デジタル署名

RSAまたはECDSA鍵を使用したCMS/PKCS#7デジタル署名でPDFに署名します。

基本的な署名

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"),
)

証明書チェーンとタイムスタンプ付き

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)署名の理由
signature.WithLocation(location)署名の場所
signature.WithTimestamp(tsaURL)RFC 3161タイムスタンプ局のURL
signature.WithSignTime(t)明示的な署名時刻(デフォルト: 現在時刻)