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

rich-id / pdf-template-bundle / #19

11 Mar 2024 11:38AM UTC coverage: 0.0%. Remained the same
#19

push

Matthias Devlamynck
Update dependencies

0 of 179 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Domain/Pdf/Trait/PdfProtectionTrait.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace RichId\PdfTemplateBundle\Domain\Pdf\Trait;
6

7
use mikehaertl\pdftk\Pdf;
8

9
trait PdfProtectionTrait
10
{
11
    use PdfTempFileTrait;
12

13
    private function internalProtectPdf(string $source): string
14
    {
15
        return $this->withTempDir(function (string $tempDir) use ($source) {
×
16
            $pdf = new Pdf();
×
17
            $pdf->ignoreWarnings = true;
×
18

19
            $pdf->addFile($this->copySource($source, $tempDir, 0));
×
20

21
            $pdf->setPassword(self::randomPassword());
×
22
            $pdf->allow('Printing DegradedPrinting');
×
23

24
            $result = $pdf->toString();
×
25

26
            if (\is_bool($result)) {
×
27
                throw new \Exception('Failed to generate pdf file');
×
28
            }
29

30
            return $result;
×
31
        });
×
32
    }
33

34
    private static function randomPassword(int $length = 32): string
35
    {
36
        $string = '';
×
37

38
        while (($len = strlen($string)) < $length) {
×
39
            $size = $length - $len;
×
40
            $bytes = random_bytes($size);
×
41
            $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
×
42
        }
43

44
        return $string;
×
45
    }
46
}
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

© 2025 Coveralls, Inc