Initial commit

This commit is contained in:
2026-08-20 11:41:17 +00:00
commit 6949695eac
2334 changed files with 646393 additions and 0 deletions
@@ -0,0 +1,47 @@
# External Preflight Matrix
This folder contains a minimal scaffold to generate one sample PDF for each supported mode and run external validators.
## Included scripts
- `generate_mode_samples.php` generates sample PDFs for:
- `pdfx`, `pdfx1a`, `pdfx3`, `pdfx4`, `pdfx5`
- `pdfua`, `pdfua1`, `pdfua2`
- `run_preflight_matrix.sh` runs:
- `qpdf --check` when `qpdf` is available
- `verapdf --format text --flavour ua1|ua2` for PDF/UA samples when `verapdf` is available
- a custom PDF/X validator command when `PDFX_VALIDATOR_CMD` is set
## Usage
From the repository root:
```bash
make preflight
```
Optional PDF/X validator hook:
```bash
PDFX_VALIDATOR_CMD='my-pdfx-validator --mode "$MODE" "$FILE"' make preflight
```
The script runs the command through `bash -lc` with these environment variables set per file:
- `MODE`: the current conformance mode, for example `pdfx4`
- `FILE`: the generated sample PDF path
- `REPORT`: the report file path under `target/preflight/report/`
Optional custom output directory:
```bash
bash resources/preflight/run_preflight_matrix.sh /tmp/tc-lib-pdf-preflight
```
Reports are written under `target/preflight/report/` (or the custom output path).
## Notes
- This is a tooling scaffold for repeatable external validation runs.
- veraPDF is used here as an explicit PDF/UA validator, not as a PDF/X validator.
- Final compliance claims still require profile-specific preflight policies and manual review using your selected validation authority.
@@ -0,0 +1,49 @@
<?php
/**
* Generate one minimal PDF sample per supported PDF/X and PDF/UA mode.
*
* Usage:
* php resources/preflight/generate_mode_samples.php [output-directory]
*/
declare(strict_types=1);
require __DIR__ . '/../../vendor/autoload.php';
define('K_PATH_FONTS', (string) \realpath(__DIR__ . '/../../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
$outDir = $argv[1] ?? (__DIR__ . '/../../target/preflight');
if (!\is_dir($outDir) && !\mkdir($outDir, 0775, true) && !\is_dir($outDir)) {
\fwrite(STDERR, "Unable to create output directory: {$outDir}\n");
exit(1);
}
$modes = [
'pdfx',
'pdfx1a',
'pdfx3',
'pdfx4',
'pdfx5',
'pdfua',
'pdfua1',
'pdfua2',
];
foreach ($modes as $mode) {
$pdf = new \Com\Tecnick\Pdf\Tcpdf('mm', true, false, true, $mode);
$font = $pdf->font->insert($pdf->pon, 'helvetica', '', 12);
$page = $pdf->addPage();
$pdf->page->addContent($font['out']);
$title = \strtoupper($mode);
$pdf->addHTMLCell('<h1>Conformance sample</h1><p>Mode: ' . $title . '</p>', 15, 20, 180);
$rawPdf = $pdf->getOutPDFString();
$outFile = $outDir . '/mode-' . $mode . '.pdf';
if (\file_put_contents($outFile, $rawPdf) === false) {
\fwrite(STDERR, "Unable to write sample file: {$outFile}\n");
exit(1);
}
\fwrite(STDOUT, $mode . "\t" . $outFile . "\n");
}
@@ -0,0 +1,94 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
OUT_DIR="${1:-${ROOT_DIR}/target/preflight}"
REPORT_DIR="${OUT_DIR}/report"
GENERATOR="${ROOT_DIR}/resources/preflight/generate_mode_samples.php"
PDFX_MODES=(pdfx pdfx1a pdfx3 pdfx4 pdfx5)
PDFUA_MODES=(pdfua pdfua1 pdfua2)
ALL_MODES=("${PDFX_MODES[@]}" "${PDFUA_MODES[@]}")
VERAPDF_BIN="${VERAPDF_BIN:-$(command -v verapdf || true)}"
QPDF_BIN="${QPDF_BIN:-$(command -v qpdf || true)}"
PDFX_VALIDATOR_CMD="${PDFX_VALIDATOR_CMD:-}"
pdfua_flavour() {
case "$1" in
pdfua|pdfua1)
printf 'ua1'
;;
pdfua2)
printf 'ua2'
;;
*)
return 1
;;
esac
}
mkdir -p "${OUT_DIR}" "${REPORT_DIR}"
echo "[preflight] generating conformance samples in ${OUT_DIR}"
php "${GENERATOR}" "${OUT_DIR}" >/dev/null
failures=0
checks=0
if [[ -n "${QPDF_BIN}" ]]; then
echo "[preflight] running qpdf structural checks"
for mode in "${ALL_MODES[@]}"; do
file="${OUT_DIR}/mode-${mode}.pdf"
report="${REPORT_DIR}/qpdf-${mode}.txt"
if "${QPDF_BIN}" --check "${file}" >"${report}" 2>&1; then
echo "[ok] qpdf ${mode}"
checks=$((checks + 1))
else
echo "[fail] qpdf ${mode} (see ${report})"
failures=$((failures + 1))
fi
done
else
echo "[skip] qpdf not found; install qpdf to enable structural validation"
fi
if [[ -n "${PDFX_VALIDATOR_CMD}" ]]; then
echo "[preflight] running configured PDF/X validator"
for mode in "${PDFX_MODES[@]}"; do
file="${OUT_DIR}/mode-${mode}.pdf"
report="${REPORT_DIR}/pdfx-validator-${mode}.txt"
if MODE="${mode}" FILE="${file}" REPORT="${report}" bash -lc "${PDFX_VALIDATOR_CMD}" >"${report}" 2>&1; then
echo "[ok] pdfx-validator ${mode}"
checks=$((checks + 1))
else
echo "[fail] pdfx-validator ${mode} (see ${report})"
failures=$((failures + 1))
fi
done
else
echo "[skip] no PDF/X profile validator configured; set PDFX_VALIDATOR_CMD to enable PDF/X authority checks"
fi
if [[ -n "${VERAPDF_BIN}" ]]; then
echo "[preflight] running veraPDF PDF/UA profile checks"
for mode in "${PDFUA_MODES[@]}"; do
file="${OUT_DIR}/mode-${mode}.pdf"
report="${REPORT_DIR}/verapdf-${mode}.txt"
flavour="$(pdfua_flavour "${mode}")"
if "${VERAPDF_BIN}" --format text --flavour "${flavour}" "${file}" >"${report}" 2>&1; then
echo "[ok] veraPDF ${mode} (${flavour})"
checks=$((checks + 1))
else
echo "[fail] veraPDF ${mode} (${flavour}) (see ${report})"
failures=$((failures + 1))
fi
done
else
echo "[skip] veraPDF not found; install verapdf to enable explicit PDF/UA profile validation"
fi
echo "[preflight] completed checks=${checks} failures=${failures}"
if [[ ${failures} -gt 0 ]]; then
exit 1
fi