Module: Pdfrb::Validator

Defined in:
lib/pdfrb/validator.rb

Overview

Pre-write document validation. Checks structural integrity before serialization to prevent producing corrupt PDFs. Raises Pdfrb::ValidationError with a descriptive message.

Class Method Summary collapse

Class Method Details

.validate(document) ⇒ Array<String>

Validate without raising. Returns array of error strings.

Returns:

  • (Array<String>)


22
23
24
25
26
27
28
# File 'lib/pdfrb/validator.rb', line 22

def validate(document)
  errors = []
  check_catalog(document, errors)
  check_pages(document, errors)
  check_references(document, errors)
  errors
end

.validate!(document) ⇒ true

Validate a document before writing. Returns true if valid, raises Pdfrb::ValidationError otherwise.

Parameters:

Returns:

  • (true)

Raises:



13
14
15
16
17
18
# File 'lib/pdfrb/validator.rb', line 13

def validate!(document)
  errors = validate(document)
  return true if errors.empty?

  raise Pdfrb::ValidationError, errors.join("; ")
end