[$title, $bodyFont, $description]) { $content = new StreamObject(new ContentStreams( new BeginTextObject(), new SetTextFontAndSize(new NameType('F1'), new NumericType(18)), new MoveTextPosition(new NumericType(42), new NumericType(778)), new ShowText(new LiteralString($title)), new SetTextFontAndSize(new NameType($bodyFont), new NumericType(10)), new MoveTextPosition(new NumericType(0), new NumericType(-42)), new ShowText(new LiteralString($description)), new MoveTextPosition(new NumericType(0), new NumericType(-32)), new ShowText(new LiteralString('Page ' . ($index + 1) . ' / 3 - Annexe F, ISO 32000-1:2008')), new EndTextObject(), )); $leaf = new PageObject(null, $index === 0 ? null : new IndirectReference($following), $content); $pages->addKid($leaf); $leaves[] = $leaf; } // 3. The outline and information are document objects. They are grouped // after pages; named hint tables provide their byte ranges. $outline = new OutlineDictionary(); foreach ($leaves as $index => $leaf) { $outline->addItem(new OutlineItem(new TextString('Page ' . ($index + 1)), new Fit($leaf))); } $catalog = new DocumentCatalog($pages, new Outlines(new IndirectReference($outline))); $information = new DocumentInformation(new Title(new TextString('Un document PDF linearise, objet par objet'))); $file = new FileStructure( new FileHeader('1.7'), new FileBody($catalog), new IndirectReference($catalog), new DictionaryType(new Entry(new NameType('Info'), new IndirectReference($information))) ); // 4. The writer calculates order, renumbers references in its own context, // encodes binary hints and writes exact offsets. The supplied graph remains // intact; no external program is needed to produce these bytes. $path = $argv[1] ?? __DIR__ . '/linearized.pdf'; (new LinearizedWriter())->writeTo($file, $path); echo $path . PHP_EOL;