Skip to content

Commit

Permalink
New PDF optput method for XOBjects
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Aug 17, 2024
1 parent f3a1c5b commit b529128
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.15
2.1.0
36 changes: 36 additions & 0 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*
* @phpstan-import-type ImageBaseData from \Com\Tecnick\Pdf\Image\Import
* @phpstan-import-type ImageRawData from \Com\Tecnick\Pdf\Image\Import
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
abstract class Output
{
Expand Down Expand Up @@ -270,6 +272,40 @@ public function getXobjectDict(): string
return $out;
}

/**
* Return XObjects Dictionary.
*
* @param array<int> $keys Image IDs.
*/
public function getXobjectDictByKeys(array $keys): string
{
if (empty($keys)) {
return '';
}

$out = '';

foreach ($keys as $iid) {
$key = 'IMG' . $iid;
if (!empty($this->xobjdict[$key])) {
$out .= ' /' . $key . ' ' . $this->xobjdict[$key] . ' 0 R';
continue;
}
$key = 'IMGplain' . $iid;
if (!empty($this->xobjdict[$key])) {
$out .= ' /' . $key . ' ' . $this->xobjdict[$key] . ' 0 R';
continue;
}
$key = 'IMGmask' . $iid;
if (!empty($this->xobjdict[$key])) {
$out .= ' /' . $key . ' ' . $this->xobjdict[$key] . ' 0 R';
continue;
}
}

return $out;
}

/**
* Get the PDF output string for ICC object.
*
Expand Down
6 changes: 6 additions & 0 deletions test/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,11 @@ public function testAdd(): void
. ' /IMG15 31 0 R /IMGplain16 33 0 R /IMG17 35 0 R /IMG18 37 0 R',
$xobjectDict
);

$xdByKeys = $import->getXobjectDictByKeys([2,3]);
$this->assertEquals(
' /IMG2 12 0 R /IMG3 13 0 R',
$xdByKeys
);
}
}

0 comments on commit b529128

Please sign in to comment.