currentReaderId = null; foreach (\array_keys($this->readers) as $readerId) { $reader = $this->getPdfReader($readerId); $parser = $reader->getParser(); $this->currentReaderId = $readerId; $ocProperties = PdfType::resolve(PdfDictionary::get($parser->getCatalog(), 'OCProperties'), $parser); if (!($ocProperties instanceof PdfNull)) { $ocProperties = PdfDictionary::ensure($ocProperties); $this->_newobj(); $this->ocPropertiesN = $this->n; $this->writePdfType($ocProperties); $this->_out('endobj'); break; } } parent::_putresources(); } protected function _putcatalog() { $this->_out('/OCProperties ' . $this->ocPropertiesN . ' 0 R'); parent::_putcatalog(); } } $files = $_GET['f']; if (!is_array($files)) { $files = [$files]; } $pdf = new FpdiWithLayers(); foreach ($files as $file) { $pageCount = $pdf->setSourceFile($file); for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { $pdf->AddPage(); $pdf->useTemplate($pdf->importPage($pageNo), ['adjustPageSize' => true]); } } $pdf->Output('F', 'import-layers.pdf'); ?>