Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
dbfcce9
Write PDF/A-2b and PDF/A-2u documents that keep their transparency
jakejackson1 Sep 22, 2026
3c85884
Validate documents with veraPDF in a Conformance workflow
jakejackson1 Sep 22, 2026
860e8ca
Default PDF/A documents to PDF/A-2b, and say what each version is for
jakejackson1 Sep 22, 2026
a0d7872
Validate CMYK, cmyka() and attachments in the PDF/A conformance tests
jakejackson1 Sep 22, 2026
230972a
Round every patch mesh percentage, and check for veraPDF once
jakejackson1 Sep 22, 2026
93c0dbe
Keep an annotation's subject under PDF/A-2 and PDF/A-3 (#350)
jakejackson1 Sep 22, 2026
75545d6
Allow layers and hidden content under PDF/A-2 and PDF/A-3 (#351)
jakejackson1 Sep 22, 2026
39079b1
Give each annotation its object numbers once, instead of predicting t…
jakejackson1 Sep 22, 2026
f032ada
Keep a PDF/A-1b document to what PDF/A-1 allows of fonts, SVG opacity…
jakejackson1 Sep 23, 2026
ba478e8
Write a PDF/A-3 annotation's file as an associated file, so it passes…
jakejackson1 Sep 22, 2026
640e2ed
Name an annotation's file from the end of a Windows path, not from th…
jakejackson1 Sep 23, 2026
c14e09c
Paint SVG gradient stops opaque under PDF/A-1b, and write only the vi…
jakejackson1 Sep 23, 2026
be54d7d
Give every active form widget its own appearance, and ask the viewer …
jakejackson1 Sep 23, 2026
5cfcc1d
Attach allow-listed files in the PDF/A tests, and name PDF/A-1b where…
jakejackson1 Sep 23, 2026
6b49d34
Expect the path a PDF/A-2 warning names with forward slashes, as mPDF…
jakejackson1 Sep 23, 2026
656219b
Leave screen-only and unwritable hidden content out under PDFAauto an…
jakejackson1 Sep 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Conformance Tests"

on:
pull_request:
push:
branches:
- "master"
- "development"
- "test"
- "gravitypdf"

jobs:

tests:

name: "Tests"

runs-on: ubuntu-latest

env:
# The veraPDF release to install; the cache is keyed on it
VERAPDF_VERSION: "1.30.2"

steps:
- name: "Checkout"
uses: "actions/checkout@v7"

- name: "Install Java"
uses: "actions/setup-java@v6"
with:
distribution: "temurin"
java-version: "21"

- name: "Cache veraPDF"
id: "verapdf-cache"
uses: "actions/cache@v6"
with:
path: "~/verapdf"
key: "verapdf-${{ env.VERAPDF_VERSION }}"

- name: "Install veraPDF"
if: steps.verapdf-cache.outputs.cache-hit != 'true'
run: |
curl -sSfL -o verapdf-installer.zip "https://software.verapdf.org/releases/${VERAPDF_VERSION%.*}/verapdf-greenfield-${VERAPDF_VERSION}-installer.zip"
unzip -q verapdf-installer.zip
echo "INSTALL_PATH=$HOME/verapdf" > verapdf.properties
java -jar "verapdf-greenfield-${VERAPDF_VERSION}/verapdf-izpack-installer-${VERAPDF_VERSION}.jar" -options verapdf.properties
rm -r verapdf-installer.zip verapdf.properties "verapdf-greenfield-${VERAPDF_VERSION}"

- name: "Put veraPDF on the PATH"
run: echo "$HOME/verapdf" >> "$GITHUB_PATH"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.5"
extensions: "mbstring, gd, bcmath, bz2"
tools: composer:v2
ini-values: error_reporting=-1

- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

# A skip here means veraPDF could not be run, so it fails the job
- name: "Conformance Tests"
run: composer test -- --group=conformance --fail-on-skipped
47 changes: 47 additions & 0 deletions data/iccprofiles/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Bundled ICC profiles — third-party notices

mPDF ships the ICC profiles in this directory as **verbatim, unmodified** data
files. Each is covered by its own licence (below), independently of mPDF's own
licence — they are aggregated data assets, not part of mPDF's source code, and
are redistributed here under the terms their publishers grant. Do not alter these
files; ship them byte-for-byte.

To use a different output condition (e.g. your house print profile), set the
`ICCProfile` config key to the path of your own `.icc` file — it overrides the
bundled default and nothing here is embedded.

---

## sRGB_IEC61966-2-1.icc

- **Colour space:** RGB (used as the PDF/A and default output-intent profile).
- **Publisher / copyright:** International Color Consortium.
- **Embedded copyright string:** `Copyright International Color Consortium, 2009`.
- **Terms:** Distributed by the ICC as a freely redistributable reference
profile; may be copied, embedded and redistributed without restriction.
- **Source:** <https://www.color.org/srgbprofiles.xalter>

## SWOP2006_Coated3v2.icc

- **Colour space:** CMYK, device class `prtr` (printer), ICC v2.
A CMYK output intent: point `ICCProfile` at it, with `restrictColorSpace` set
to 3, to write a CMYK PDF/A document. Nothing embeds it unless asked.
Represents U.S. web-coated (SWOP) publication printing, 2006, grade 3 coated.
- **Publisher:** IDEAlliance, with permission of X-Rite, Inc.
- **Copyright:** X-Rite, Inc.
- **Licence (verbatim, as embedded in the profile's `cprt` tag and published in
the ICC Profile Registry):**

> Copyright X-Rite, Inc.. This profile is made available by IDEAlliance, with
> permission of X-Rite, Inc., and may be used, embedded, exchanged, and shared
> without restriction. It may not be altered, or sold without written
> permission of IDEAlliance.

- **Source:** <https://registry.color.org/profile-registry/SWOP2006_Coated3v2>
- **MD5:** `7fbad4c0ae1cb7195c34bfc20e623437`

This profile is freely redistributable and embeddable under the terms above.
It is **not** an open-source/free-software licence (redistribution is
permitted, but modification and sale of the profile itself are not without
IDEAlliance's written permission), so it is bundled unmodified as a separate
data file and is not covered by mPDF's own licence.
Binary file added data/iccprofiles/SWOP2006_Coated3v2.icc
Binary file not shown.
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ parameters:
-
message: '#^Variable \$radio_background_color might not be defined\.$#'
identifier: variable.undefined
count: 2
count: 1
path: src/Form.php

-
message: '#^Variable \$radio_color might not be defined\.$#'
identifier: variable.undefined
count: 10
count: 1
path: src/Form.php

-
Expand Down
42 changes: 29 additions & 13 deletions src/Color/ColorSpaceRestrictor.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,15 @@ private function restrictRgbaColorSpace($c, $color, &$PDFAXwarnings = [])
{
if ($this->mpdf->PDFX || ($this->mpdf->PDFA && $this->mpdf->restrictColorSpace == 3)) {
if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
$PDFAXwarnings[] = "RGB color with transparency specified '" . $color . "' (converted to CMYK without transparency)";
$PDFAXwarnings[] = "RGB color with transparency specified '" . $color . "' (converted to CMYK" . ($this->mpdf->transparencyAllowed() ? ')' : ' without transparency)');
}
$c = $this->colorModeConverter->rgb2cmyk($c);
$c = [4, $c[1], $c[2], $c[3], $c[4]];
$c = $this->withAllowedAlpha($this->colorModeConverter->rgb2cmyk($c));
} elseif ($this->mpdf->PDFA && $this->mpdf->restrictColorSpace != 3) {
if (!$this->mpdf->PDFAauto) {
// An opaque rgba() loses nothing by dropping its alpha
if (!$this->mpdf->PDFAauto && !$this->mpdf->transparencyAllowed() && $c[4] < 100) {
$PDFAXwarnings[] = "RGB color with transparency specified '" . $color . "' (converted to RGB without transparency)";
}
$c = $this->colorModeConverter->rgb2cmyk($c);
$c = [4, $c[1], $c[2], $c[3], $c[4]];
$c = $this->withAllowedAlpha($c);
} elseif ($this->mpdf->restrictColorSpace == 1) {
$c = $this->colorModeConverter->rgb2gray($c);
} elseif ($this->mpdf->restrictColorSpace == 3) {
Expand All @@ -190,17 +189,15 @@ private function restrictRgbaColorSpace($c, $color, &$PDFAXwarnings = [])
private function restrictCmykaColorSpace($c, $color, &$PDFAXwarnings = [])
{
if ($this->mpdf->PDFA && $this->mpdf->restrictColorSpace != 3) {
if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
$PDFAXwarnings[] = "CMYK color with transparency specified '" . $color . "' (converted to RGB without transparency)";
if (!$this->mpdf->PDFAauto) {
$PDFAXwarnings[] = "CMYK color with transparency specified '" . $color . "' (converted to RGB" . ($this->mpdf->transparencyAllowed() ? ')' : ' without transparency)');
}
$c = $this->colorModeConverter->cmyk2rgb($c);
$c = [3, $c[1], $c[2], $c[3]];
$c = $this->withAllowedAlpha($this->colorModeConverter->cmyk2rgb($c));
} elseif ($this->mpdf->PDFX || ($this->mpdf->PDFA && $this->mpdf->restrictColorSpace == 3)) {
if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) {
if (!$this->mpdf->transparencyAllowed() && $c[5] < 100 && (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto))) {
$PDFAXwarnings[] = "CMYK color with transparency specified '" . $color . "' (converted to CMYK without transparency)";
}
$c = $this->colorModeConverter->cmyk2rgb($c);
$c = [3, $c[1], $c[2], $c[3]];
$c = $this->withAllowedAlpha($c);
} elseif ($this->mpdf->restrictColorSpace == 1) {
$c = $this->colorModeConverter->cmyk2gray($c);
} elseif ($this->mpdf->restrictColorSpace == 2) {
Expand All @@ -210,4 +207,23 @@ private function restrictCmykaColorSpace($c, $color, &$PDFAXwarnings = [])
return $c;
}

/**
* Drops the alpha from an rgba() or cmyka() colour, unless the document allows transparency
*
* @param mixed[] $c
*
* @return mixed[]
*/
private function withAllowedAlpha(array $c)
{
if ($this->mpdf->transparencyAllowed()) {
return $c;
}

array_pop($c);
$c[0] -= 2; // 5 (RGBa) to 3 (RGB), 6 (CMYKa) to 4 (CMYK)

return $c;
}

}
19 changes: 15 additions & 4 deletions src/Config/ConfigVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,25 @@ public function __construct()
// Overrides warnings making changes when possible to force PDFX1-a compliance
'PDFXauto' => false,

// PDFA1-b Compliant files
// true=Forces compliance with PDFA-1b spec
// PDF/A Compliant files
// true=Forces compliance with the PDF/A part and level PDFAversion names
// Can use with 'restrictColorSpace'=3 (for a CMYK file)
// Any other settings, uses RGB profile
'PDFA' => false,
// Overrides warnings making changes when possible to force PDFA1-b compliance
// Overrides warnings making changes when possible to force PDF/A compliance
'PDFAauto' => false,
'PDFAversion' => '1-B',
// The PDF/A part and conformance level to write. B (basic) preserves how the document looks; U (Unicode)
// also maps every character to Unicode, so its text can be searched and copied reliably
// 1-B PDF/A-1b (ISO 19005-1, PDF 1.4). For archives that accept only the first part: no transparency,
// watermarks or attachments, and translucent content is drawn opaque
// 2-B PDF/A-2b (ISO 19005-2, PDF 1.7). The general choice for long-term archiving, and the level
// archives and validators most often expect. Allows transparency, and attachments that are PDF/A
// 2-U PDF/A-2u. PDF/A-2b with searchable, copyable text
// 3-B PDF/A-3b (ISO 19005-3). PDF/A-2b that may carry attachments of any type (see SetAssociatedFiles),
// as e-invoices such as ZUGFeRD, Factur-X and XRechnung carry their XML
// 3-U PDF/A-3u. PDF/A-3b with searchable, copyable text
// Level A (accessible) needs tagged PDF, which mPDF does not write
'PDFAversion' => '2-B',

// Colour profile OutputIntent
// sRGB_IEC61966-2-1 (=default if blank and PDFA), or other added .icc profile
Expand Down
12 changes: 7 additions & 5 deletions src/Fonts/FontSubsetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,22 +403,23 @@ private function buildSubset(array $subset, $useOTL)
* @param int $TTCfontID Which font of a TrueType Collection, or 0 for a plain font
* @param bool $debug Whether to check the font's own tables as they are read
* @param int $useOTL Whether the document laid the font out with its OTL tables
* @param bool $oneCmapSubtable Whether the cmap may hold only its (3,0) subtable, as PDF/A-1 requires
*
* @return string The font program to embed
*
* @throws \Mpdf\Exception\FontException Where the font carries no Unicode cmap to read, or subsets
* into more segments than the format 4 subtable's length
* field can state
*/
public function makeSubsetSIP($file, array $subset, $TTCfontID = 0, $debug = false, $useOTL = 0)
public function makeSubsetSIP($file, array $subset, $TTCfontID = 0, $debug = false, $useOTL = 0, $oneCmapSubtable = false)
{
$this->open($file);

// Closed however the build ends: see makeSubset
try {
$this->readTableDirectory($TTCfontID, $debug);

return $this->buildSubsetSIP($subset, $TTCfontID, $useOTL);
return $this->buildSubsetSIP($subset, $TTCfontID, $useOTL, $oneCmapSubtable);
} finally {
$this->reader->close();
}
Expand All @@ -427,7 +428,7 @@ public function makeSubsetSIP($file, array $subset, $TTCfontID = 0, $debug = fal
/**
* @return string See makeSubsetSIP
*/
private function buildSubsetSIP(array $subset, $TTCfontID, $useOTL)
private function buildSubsetSIP(array $subset, $TTCfontID, $useOTL, $oneCmapSubtable)
{
list($indexToLocFormat, $numberOfHMetrics, $numGlyphs) = $this->readHeaders();

Expand Down Expand Up @@ -558,11 +559,12 @@ private function buildSubsetSIP(array $subset, $TTCfontID, $useOTL)
// cmap - Character to glyph mapping
$format6Length = 10 + 2 * count($subset);

if ($format6Length > 0xFFFF) {
if ($format6Length > 0xFFFF || $oneCmapSubtable) {
// A format 6 subtable states its length in a uint16, so past 32,762 characters it cannot be
// written. It maps the same codes to the same glyphs as the format 4 subtable, and a reader
// looks a symbolic TrueType font's codes up in (3,0) before (1,0) (ISO 32000-1, 9.6.6.4),
// so leave (1,0) out rather than refuse a font the format 4 subtable maps whole.
// so leave (1,0) out rather than refuse a font the format 4 subtable maps whole, or one
// PDF/A-1 allows a single subtable.
$cmapstr = TableWriter::uint16s([0, 1, 3, 0]) . TableWriter::uint32(12) . $cmapstr4;
} else {
$cmapstr = TableWriter::uint16s([0, 2, 1, 0]) . TableWriter::uint32(20)
Expand Down
Loading
Loading