Skip to content

Commit

Permalink
[Standard] PDF/X-1a
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed Jul 7, 2017
1 parent 379da04 commit 2201a18
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 44 deletions.
16 changes: 16 additions & 0 deletions Standard/StandardInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Padam87\PdfPreflight\Standard;

use Padam87\PdfPreflight\Rule\RuleInterface;
use Smalot\PdfParser\Document;

interface StandardInterface
{
/**
* @return RuleInterface[]
*/
public function getRules(): array;

public function validate(Document $document): array;
}
67 changes: 67 additions & 0 deletions Standard/X1a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Padam87\PdfPreflight\Standard;

use Padam87\PdfPreflight\Rule\NoRgbImages;
use Padam87\PdfPreflight\Rule\NoRgbText;
use Smalot\PdfParser\Document;


/**
* The PDF/X-1a standard
*
* - [ ] PDF must be version 1.3 or earlier
* - [ ] Page must not be separated
* - [ ] OutputIntent must be present
* - [ ] OutputIntent must contain exactly one PDF/X entry
* - [ ] OutputConditionIdentifier required in PDF/X OutputIntent
* - [ ] Destination profile must be embedded or Registry Name must be filled out
* - [ ] OutputIntent Info key must be present
* - [ ] Destination profile must be ICC output profile (type ‘prtr’)
* - [x] Only DeviceCMYK and spot colors allowed
* - [ ] Fonts must be embedded
* - [ ] LZW compression prohibited
* - [ ] Trapped key must be True or False
* - [ ] GTS_PDFXVersion key must be present
* - [ ] Invalid GTS_PDFXVersion (PDF/X-1a)
* - [ ] Invalid GTS_PDFXConformance (PDF/X-1a)
* - [ ] CreationDate, ModDate and Title required
* - [ ] Document ID must be present in PDF trailer
* - [ ] Either TrimBox or ArtBox must be present
* - [ ] Page boxes must be nested properly
* - [ ] Transfer curves prohibited
* - [ ] Halftone must be of Type 1 or 5
* - [ ] Halftone Name key prohibited
* - [ ] Embedded PostScript prohibited
* - [ ] Encryption prohibited
* - [ ] Alternate image must not be default for printing
* - [ ] Annotation and Acrobat form elements must be outside of TrimBox and BleedBox
* - [ ] Actions and JavaScript prohibited
* - [ ] Operators not defined in PDF 1.3 prohibited
* - [ ] File specifications not allowed
* - [ ] Transparency not allowed
*/
class X1a implements StandardInterface
{
/**
* {@inheritdoc}
*/
public function getRules(): array
{
return [
new NoRgbImages(),
new NoRgbText(),
];
}

public function validate(Document $document): array
{
$errors = [];

foreach ($this->getRules() as $rule) {
$errors[get_class($rule)] = $rule->validate($document);
}

return $errors;
}
}
49 changes: 5 additions & 44 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@

include 'vendor/autoload.php';

use Padam87\PdfPreflight\Rule\MaxInkDensityImage;
use Padam87\PdfPreflight\Rule\MaxInkDensityText;
use Padam87\PdfPreflight\Rule\NoRgbImages;
use Padam87\PdfPreflight\Rule\ImageMinDpi;
use Padam87\PdfPreflight\Rule\NoRgbText;
use Padam87\PdfPreflight\Rule\RuleInterface;
use Padam87\PdfPreflight\Standard\X1a;
use Smalot\PdfParser\Object as XObject;
use Smalot\PdfParser\Parser;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\CliDumper;
Expand All @@ -35,45 +29,12 @@
$dumper->dump($cloner->cloneVar($var));
});

/** @var RuleInterface[] $rules */
$rules = [
new ImageMinDpi(),
new NoRgbImages(),
new NoRgbText(),
new MaxInkDensityImage(300),
new MaxInkDensityText(100),
];

$stopwatch = new Stopwatch();
$stopwatch->start('parse');

$parser = new Parser();
//$document = $parser->parseFile('./gls.pdf');
$document = $parser->parseFile('./test.pdf');

$event = $stopwatch->stop('parse');

dump($event->getDuration());

$stopwatch->start('preflight');

foreach ($rules as $rule) {
$errors = $rule->validate($document);

$event = $stopwatch->lap('preflight');
$periods = $event->getPeriods();
$period = end($periods);

dump(
[
'rule' => get_class($rule),
'errors' => $errors,
'duration' => $period->getDuration(),
]
);
}
//$document = $parser->parseFile('./test.pdf');
$document = $parser->parseFile('./hotel.pdf');

$event = $stopwatch->stop('preflight');
$standard = new X1a();

dump($event->getDuration());
dump($standard->validate($document));

1 comment on commit 2201a18

@Padam87
Copy link
Owner Author

@Padam87 Padam87 commented on 2201a18 Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1

Please sign in to comment.