Skip to content

Commit bc523a9

Browse files
authored
Merge branch 'main' into feature/pdf-samples-extended
2 parents 9a34ddc + 86d1a42 commit bc523a9

6 files changed

Lines changed: 173 additions & 0 deletions

File tree

src/Document/Dictionary/DictionaryValue/Name/FilterNameValue.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PrinsFrank\PdfParser\Document\Dictionary\DictionaryKey\DictionaryKey;
88
use PrinsFrank\PdfParser\Document\Dictionary\DictionaryValue\Integer\IntegerValue;
99
use PrinsFrank\PdfParser\Document\Document;
10+
use PrinsFrank\PdfParser\Document\Filter\Decode\ASCII85Decode;
1011
use PrinsFrank\PdfParser\Document\Filter\Decode\CCITTFaxDecode;
1112
use PrinsFrank\PdfParser\Document\Filter\Decode\FlateDecode;
1213
use PrinsFrank\PdfParser\Document\Filter\Decode\LZWFlatePredictorValue;
@@ -54,6 +55,7 @@ public function decodeBinary(string $content, ?Dictionary $dictionary, ?Document
5455
$decodeParams->getValueForKey(DictionaryKey::K, IntegerValue::class)->value
5556
?? throw new ParseFailureException('Missing K'),
5657
),
58+
self::ASCII_85_DECODE => ASCII85Decode::decodeBinary($content),
5759
default => throw new ParseFailureException(sprintf('Content "%.100s..." cannot be decoded for filter "%s"', $content, $this->name))
5860
};
5961
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PrinsFrank\PdfParser\Document\Filter\Decode;
4+
5+
use PrinsFrank\PdfParser\Exception\RuntimeException;
6+
7+
class ASCII85Decode {
8+
/** @throws RuntimeException */
9+
public static function decodeBinary(string $string): string {
10+
file_put_contents(__DIR__ . '/ascii85.txt', $string);
11+
$string = trim($string);
12+
if (str_starts_with($string, '<~') && str_ends_with($string, '~>')) {
13+
$string = substr($string, 2, -2);
14+
}
15+
16+
$string = preg_replace('/\s+/', '', $string)
17+
?? throw new RuntimeException('An unexpected error occurred while sanitizing ASCII85 string');
18+
$length = strlen($string);
19+
$decoded = $block = '';
20+
for ($i = 0; $i < $length; ++$i) {
21+
$char = $string[$i];
22+
if ($char === 'z') {
23+
$decoded .= "\0\0\0\0";
24+
continue;
25+
}
26+
27+
$block .= $char;
28+
if (strlen($block) === 5) {
29+
$value = 0;
30+
for ($j = 0; $j < 5; ++$j) {
31+
$value = $value * 85 + (ord($block[$j]) - 33);
32+
}
33+
34+
$decoded .= pack('N', $value);
35+
$block = '';
36+
}
37+
}
38+
39+
if ($block !== '') {
40+
$padding = 5 - strlen($block);
41+
$block = str_pad($block, 5, 'u');
42+
$value = 0;
43+
for ($i = 0; $i < 5; ++$i) {
44+
$value = $value * 85 + (ord($block[$i]) - 33);
45+
}
46+
47+
$binaryData = pack('N', $value);
48+
$decoded .= substr($binaryData, 0, 4 - $padding);
49+
}
50+
51+
return $decoded;
52+
}
53+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# yaml-language-server: $schema=./.yml-schema.json
2+
version: '1.4'
3+
password: null
4+
title: reception0658@reseau-intersport.fr
5+
producer: 'Oracle PDF driver'
6+
author: 'Oracle Reports'
7+
creator: 'Oracle12c AS Reports Services'
8+
creationDate: 2025-07-22T10:00:03+00:00
9+
modificationDate: 2025-07-22T10:00:03+00:00
10+
pages:
11+
-
12+
content: |-
13+
CUSTOMER IE802719
14+
INTERSPORT PAIMPOL
15+
SASU C.E.F SPORTS - 17 T RUE RAYMOND PELLIER
16+
22500 PAIMPOL France
17+
CHAMPION PRODUCTS EUROPE UNLIMITED COMPANY
18+
Blanchardstown Corporate Park 2 D15 Blanchardstown - Dublin Ireland
19+
Tel. Acc.
20+
+353 (0)1 8864217 +353 (0)1 8864217Fax +353 (0)1 8665927
21+
Tel. CS
22+
IE802719
23+
DESTINATION
24+
INTERSPORT PAIMPOL
25+
ZONE DE KERPUNS CARREFOUR ILN Code: 3025810065800
26+
22500 PAIMPOL France
27+
DELIVERY NOTE
28+
DC REF.
29+
5204/165/2025/DN/5204 21/07/2025
30+
FORWARDER
31+
Label
32+
UPS - United Parcel Service S.r.l 2.0
33+
VIA G. FANTOLI, 15/2
34+
REASON
35+
20138 MILANO Milano
36+
Italy
37+
Subcontractor
38+
TRANSPORTATION COST
39+
Delivery Note N
40+
CHH/2025/70BO/058510DATE 21/07/2025
41+
COMMENTS
42+
SALES REP VORACE SAS François RAMOND
43+
ARTICLE DESCRIPTION COLOUR SIZE TOTAL
44+
ORD. NUM.
45+
35/38 39/42 43/46
46+
8 19 13
47+
4402026619
48+
3pk Sneaker Socks
49+
U20100-CHA
50+
WW001 WHT
51+
40
52+
40
53+
35/38 39/42 43/46
54+
8 17 14
55+
4402026619
56+
3pk Crew Socks
57+
U24558-CHA
58+
KK001 NBK
59+
39
60+
8 17 14
61+
4402026619
62+
WW001 WHT
63+
39
64+
78
65+
Tot. qty 118
66+
Cartons Summary
67+
250570819669 250570830162
68+
Picking List-N.
69+
CHH-2025-VE-430761
70+
Packing list W2025/PL/CHH282537
71+
Leave from
72+
PACKING Cartons Nr 2 Net Wght 16,790 Gross Wght 18,490
73+
LABEL NOTES
74+
Label
75+
FORWARDER DESTINATION
76+
CIE
77+
Signature Date Time Signature Date Time Signature Date Time
78+
1 of
79+
Copy for Customer Page 1
80+
images:
81+
- page_0_image_0.jpg
116 KB
Binary file not shown.
33.9 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace PrinsFrank\PdfParser\Tests\Unit\Document\Filter;
4+
5+
use PHPUnit\Framework\Attributes\CoversClass;
6+
use PHPUnit\Framework\TestCase;
7+
use PrinsFrank\PdfParser\Document\Filter\Decode\ASCII85Decode;
8+
9+
#[CoversClass(ASCII85Decode::class)]
10+
class ASCII85DecodeTest extends TestCase {
11+
public function testDecode(): void {
12+
static::assertSame(
13+
'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.',
14+
ASCII85Decode::decodeBinary(
15+
<<<'ASCII85'
16+
9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<
17+
DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(
18+
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(
19+
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u
20+
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c
21+
ASCII85
22+
)
23+
);
24+
static::assertSame(
25+
'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.',
26+
ASCII85Decode::decodeBinary(
27+
<<<'ASCII85'
28+
<~9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<
29+
DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(
30+
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(
31+
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u
32+
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~>
33+
ASCII85
34+
)
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)