Module: PdfOxide::PdfValidator

Defined in:
lib/pdf_oxide/pdf_validator.rb

Overview

PDF/A · PDF/X · PDF/UA compliance validation (v0.3.50).

Mirrors ‘fyi.oxide.pdf.PdfValidator`. Stateless façade.

Examples:

PdfOxide::PdfDocument.open('compliant.pdf') do |doc|
  puts PdfOxide::PdfValidator.pdf_a?(doc, level: :a1b)
end

Constant Summary collapse

PDF_A_LEVELS =

PDF/A level → cdylib wire-format integer.

Matches ‘src/ffi.rs:1225` (`0=A1b 1=A1a 2=A2b 3=A2a 4=A2u 5=A3b 6=A3a 7=A3u`). Every binding (Java, Ruby, PHP, C#, Go) sends the SAME integer for the same PDF/A level — the “B before A” intra-level order is the cdylib’s contract, not a Ruby choice.

{ a1b: 0, a1a: 1, a2b: 2, a2a: 3, a2u: 4, a3b: 5, a3a: 6, a3u: 7 }.freeze
PDF_UA_LEVELS =

PDF/UA level → cdylib wire-format integer.

Matches ‘src/ffi.rs:5538` (`level == 2 → UA-2, else UA-1`). 1-indexed, not 0-indexed; mirrors the C# `PdfUaLevel` enum.

{ ua1: 1, ua2: 2 }.freeze

Class Method Summary collapse

Class Method Details

.pdf_a?(doc, level: :a1b) ⇒ Boolean

Returns PDF/A compliance for ‘level`.

Returns:

  • (Boolean)

    PDF/A compliance for ‘level`.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pdf_oxide/pdf_validator.rb', line 30

def pdf_a?(doc, level: :a1b)
  raise ::PdfOxide::ArgumentError, 'doc cannot be nil' if doc.nil?

  ordinal = PDF_A_LEVELS.fetch(level) do
    raise ::PdfOxide::ArgumentError, "unknown PDF/A level: #{level.inspect}"
  end
  # If the native symbol is absent (older cdylib), surface a clean
  # "unavailable" verdict instead of reading an uninitialised err
  # buffer and raising a spurious ComplianceError.
  return false unless Bindings.respond_to?(:pdf_validate_pdf_a_level)

  err = ::FFI::MemoryPointer.new(:int32)
  result_ptr = Bindings.pdf_validate_pdf_a_level(doc.handle, ordinal, err)
  code = err.read_int32
  raise ComplianceError, "pdf_validate_pdf_a_level failed (#{code})" if code != 0

  compliance_verdict(result_ptr, :pdf_pdf_a_is_compliant, :pdf_pdf_a_results_free)
rescue ::FFI::NotFoundError
  false
end

.pdf_ua?(doc, level: :ua1) ⇒ Boolean

Returns PDF/UA compliance for ‘level`.

Returns:

  • (Boolean)

    PDF/UA compliance for ‘level`.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pdf_oxide/pdf_validator.rb', line 52

def pdf_ua?(doc, level: :ua1)
  raise ::PdfOxide::ArgumentError, 'doc cannot be nil' if doc.nil?

  ordinal = PDF_UA_LEVELS.fetch(level) do
    raise ::PdfOxide::ArgumentError, "unknown PDF/UA level: #{level.inspect}"
  end
  err = ::FFI::MemoryPointer.new(:int32)
  result_ptr = Bindings.pdf_validate_pdf_ua(doc.handle, ordinal, err)
  code = err.read_int32
  raise ComplianceError, "pdf_validate_pdf_ua failed (#{code})" if code != 0

  compliance_verdict(result_ptr, :pdf_pdf_ua_is_accessible, :pdf_pdf_ua_results_free)
rescue ::FFI::NotFoundError
  false
end

.validate_pdf_a(doc, level: :a1b) ⇒ Hash

Returns simplified PDF/A validation result: { compliant:, violations: }.

Returns:

  • (Hash)

    simplified PDF/A validation result: { compliant:, violations: }.



69
70
71
# File 'lib/pdf_oxide/pdf_validator.rb', line 69

def validate_pdf_a(doc, level: :a1b)
  { compliant: pdf_a?(doc, level: level), violations: [] }
end

.validate_pdf_ua(doc, level: :ua1) ⇒ Hash

Returns simplified PDF/UA validation result.

Returns:

  • (Hash)

    simplified PDF/UA validation result.



74
75
76
# File 'lib/pdf_oxide/pdf_validator.rb', line 74

def validate_pdf_ua(doc, level: :ua1)
  { compliant: pdf_ua?(doc, level: level), violations: [] }
end