Skip to content

Kernel: let callers choose the PDF version to write (1.4–2.0), and document what we read/write #223

Open

Description

@Tim81

The PDF version VellumPdf writes is not a caller decision. It is inferred from one thing —
PdfDocument.cs:600-604, and identically at :996 and in WriteLinearizedHeader at :1663:

writer.WriteAscii("%PDF-"u8);
if (Conformance == PdfConformance.None)
    writer.WriteAscii("2.0"u8);
else
    writer.WriteAscii("1.7"u8);

Two versions, chosen by whether a conformance profile was requested. A caller who needs %PDF-1.4
for an archival deposit, or %PDF-1.7 without a PDF/A profile, has no way to ask.

That gap becomes more visible once #222 lands PDF/A-4, because the Conformance == None branch stops
being a reliable proxy for "2.0 is fine".

What is wanted

An explicit PdfVersion on PdfDocument (and the Layout Document), defaulting to 2.0, accepting
1.4 through 2.0. But the header is the easy half, and stamping it alone would be a bug — this
library's whole posture is that a file should not lie about itself.

Declaring %PDF-1.4 while emitting an object stream produces a file that claims a version whose
readers cannot parse it. So the option has to constrain the writer, and where it cannot, refuse
rather than emit something inconsistent. The version-sensitive constructs already reachable:

Construct Introduced Where
Object streams 1.5 PdfDocument.UseObjectStreams (:151), opt-in, default off
Cross-reference streams 1.5 written alongside object streams
Transparency, blend modes, soft masks 1.4 canvas alpha / ExtGState
JPXDecode (JPEG 2000) 1.5 JpxImageLoader
AES-128 (/V 4, /AESV2) 1.6 encryption settings
AES-256 (/V 5, /R 6, /AESV3) 2.0 PdfEncryptionSettings
Associated files, /AFRelationship, /DPart 2.0 not implemented today

So PdfVersion = Pdf14 should turn UseObjectStreams into a validation error rather than silently
ignoring it, and should reject AES encryption. The precedent for that shape is already in the tree:
UseObjectStreams documents that it "cannot be combined with PrepareForSigning" and throws
NotSupportedException.

The interaction with Conformance needs deciding explicitly rather than by precedence accident: a
profile pins the version (PDF/A-2 ⇒ 1.7, PDF/A-4 ⇒ 2.0, PDF/A-1 ⇒ 1.4 per #218), so setting both to
incompatible values should throw at Save with a message naming both, not quietly pick one.

Reading

The reader already accepts any header — FileHeaderRule is a conformance rule, not a parse gate,
and nothing in VellumPdf.Reader rejects a file on its declared version. That is correct behaviour
for a general reader and it is simply undocumented. Worth stating in the reader guide (#187) that
1.0 through 2.0 are read, and that the header is advisory: real files routinely use constructs from
later versions than they declare, which is why the reader keys on structure rather than the header.

Documentation

None of the above is currently written down anywhere. The README, docs/architecture.md and the
Kernel guide say nothing about which PDF versions are read or written. Add:

  • Which versions are read (all of them, header advisory).
  • Which versions can be written, and how to ask for one.
  • That the default is 2.0, and that requesting a conformance profile pins the version.
  • A short table of which features are unavailable at which version, so the constraint errors are
    predictable rather than surprising.

Note on advertising

Per the discussion on #222: do not describe this as "PDF 2.0 support" in package descriptions until
the PDF/A-4 profile validates green against veraPDF in CI. Emitting a 2.0 header is not conformance,
and the two claims should not be conflated in user-facing copy.

Relates to

Activity

  1. added
    area/docs
    type/feature
    needs-design
    on Aug 28, 2026
  2. Tim81 commented on Aug 29, 2026

    @Tim81
    OwnerAuthor

    Additions from the ISO 32000-2 planning pass.

    Declaring a version constrains what may be omitted, not only what may be emitted

    The body treats the version as a constraint on constructs the writer may use — object streams,
    AES-256, transparency. There is a second direction, and it is now tracked as #325: ISO 32000-2
    clause 0.3 deprecates a set of keys this library currently writes, and it writes them under a
    %PDF-2.0 header.

    /ProcSet on every page (PdfPage.cs:107), /NeedAppearances (AcroFormBuilder.cs:101), and the
    full /Info set (PdfDocumentInfo.cs:27-32). None of them is deprecated at 1.7, so the version
    selector this issue introduces is exactly what decides whether they are emitted
    — a caller asking for
    %PDF-1.7 should still get them.

    That makes #325 a consumer of this issue rather than a parallel one, and the version-to-feature table
    here needs a deprecation column alongside its introduction column.

    The table gains rows

    Beyond the constructs already listed, from the Arlington PDF 2.0 model and clause 0.3:

    Construct Version Issue
    Structure namespaces, /NS, /RoleMapNS 2.0 #271
    Structure destinations, /SD 2.0 #273
    /UseBlackPtComp, /HTO 2.0 #256
    Associated files, /AF, /AFRelationship 2.0 #243
    Inline image /L 2.0 #258
    /Measure, /PtData on XObjects 2.0 #257
    AES-GCM, /V 6 / /R 7 ISO/TS 32003 #236
    PDF MAC, /AuthCode, /KDFSalt ISO/TS 32004 #237

    The last two are worth calling out: they are extensions to PDF 2.0 rather than part of it, so they
    are declared through a developer extensions dictionary (#235) rather than by the header version. The
    version selector needs to know the difference.

    A third source of the same constraint

    ISO/TS 32005 §5.1 independently requires that a document using structure namespaces "shall be
    versioned as PDF 2.0 using either the header or the value of the Version entry in the document
    catalog dictionary". So the tagged-PDF work in #271 pins the version too, by a different route.

    Downstream

    The version-to-feature table built here becomes the input to the auto-upgrade policy in the v3.x
    editing line — ISO 32000-2 Annex I requires that a writer never lower a file version and may raise
    it when newer features are used, which needs exactly this table to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/docsneeds-designtype/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions