• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 21017989272

15 Jan 2026 02:53AM UTC coverage: 44.43%. First build
21017989272

Pull #6436

github

web-flow
Merge 6ef45535a into db0316516
Pull Request #6436: feat: async parallel signing

415 of 962 new or added lines in 46 files covered. (43.14%)

7036 of 15836 relevant lines covered (44.43%)

4.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/lib/Service/File/Pdf/PdfParser.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9

10
namespace OCA\Libresign\Service\File\Pdf;
11

12
use OCA\Libresign\Exception\LibresignException;
13
use OCA\Libresign\Vendor\Smalot\PdfParser\Document;
14
use OCA\Libresign\Vendor\Smalot\PdfParser\Parser;
15
use OCP\IL10N;
16
use Psr\Log\LoggerInterface;
17

18
class PdfParser {
19
        public function __construct(
20
                private LoggerInterface $logger,
21
                private IL10N $l10n,
22
        ) {
23
        }
49✔
24

25
        /**
26
         * Parse PDF content and return Document object
27
         *
28
         * @param string $content PDF content
29
         * @param string $fileName File name for error messages
30
         * @return Document
31
         * @throws LibresignException
32
         */
33
        public function parse(string $content, string $fileName): Document {
34
                try {
35
                        $parser = new Parser();
17✔
36
                        return $parser->parseContent($content);
17✔
37
                } catch (\Throwable $th) {
1✔
38
                        $this->throwIfEncryptedPdf($th, $fileName);
1✔
39

40
                        $this->logger->error('PDF parsing failed: ' . $th->getMessage());
1✔
41

42
                        // TRANSLATORS %s is the file name that could not be processed as PDF
43
                        throw new LibresignException($this->l10n->t('Unable to process the file as a PDF document: %s', [$fileName]));
1✔
44
                }
45
        }
46

47
        /**
48
         * @throws LibresignException Only if the PDF is encrypted/password-protected
49
         */
50
        private function throwIfEncryptedPdf(\Throwable $th, string $fileName): void {
51
                if ($th->getMessage() !== 'Secured pdf file are currently not supported.') {
1✔
52
                        return;
1✔
53
                }
54

55
                // TRANSLATORS %s is the name of the password-protected PDF file
NEW
56
                throw new LibresignException($this->l10n->t('The file "%s" is password-protected. Please remove the protection and try again.', [$fileName]));
×
57
        }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc