-
-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathE045_encryption_and_permissions.php
More file actions
96 lines (76 loc) · 2.73 KB
/
E045_encryption_and_permissions.php
File metadata and controls
96 lines (76 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* E045_encryption_and_permissions.php
*
* @since 2026-04-27
* @category Library
* @package Pdf
* @author Nicola Asuni <info@tecnick.com>
* @copyright 2002-2026 Nicola Asuni - Tecnick.com LTD
* @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* @link https://github.com/tecnickcom/tc-lib-pdf
*
* This file is part of tc-lib-pdf software library.
*/
// NOTE: run make deps fonts in the project root to generate the dependencies and example fonts.
// autoloader when using Composer
require(__DIR__ . '/../vendor/autoload.php');
// define fonts directory
\define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts'));
// autoloader when using RPM or DEB package installation
//require ('/usr/share/php/Com/Tecnick/Pdf/autoload.php');
$fileId = \md5('E045_encryption_and_permissions');
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(
true,
$fileId,
2,
['modify', 'copy', 'annot-forms', 'assemble'],
'demo-user',
'demo-owner'
);
// main TCPDF object
$pdf = new \Com\Tecnick\Pdf\Tcpdf(
'mm', // string $unit = 'mm',
true, // bool $isunicode = true,
false, // bool $subsetfont = false,
true, // bool $compress = true,
'', // string $mode = '',
$encrypt, // ?ObjEncrypt $objEncrypt = null,
);
// ----------
$pdf->setCreator('tc-lib-pdf');
$pdf->setAuthor('Nicola Asuni');
$pdf->setSubject('tc-lib-pdf example: 045');
$pdf->setTitle('HTML Features Example');
$pdf->setKeywords('TCPDF tc-lib-pdf example Encryption and Permissions');
$pdf->setPDFFilename('E045_encryption_and_permissions.pdf');
$pdf->setViewerPreferences(['DisplayDocTitle' => true]);
$pdf->enableDefaultPageContent();
// ----------
// Insert fonts
$bfont = $pdf->font->insert($pdf->pon, 'helvetica', '', 10);
$page01 = $pdf->addPage();
$pdf->page->addContent($bfont['out']);
$html = <<<HTML
<h1>Encryption and Permissions</h1>
<p>This document demonstrates PDF encryption and permission controls using tc-lib-pdf.
The file is protected with a user password (<em>demo-user</em>) and an owner password (<em>demo-owner</em>).
Encryption restricts unauthorized access while the owner password grants full control.
The allowed permissions for this document are: <strong>modify</strong>, <strong>copy</strong>,
<strong>annot-forms</strong>, and <strong>assemble</strong>.
All other operations, such as printing, are denied.</p>
HTML;
$pdf->addHTMLCell(
$html,
20,
10,
180,
);
// ----------
// get PDF document as raw string
$rawpdf = $pdf->getOutPDFString();
// Various output modes:
//$pdf->savePDF(\dirname(__DIR__).'/target', $rawpdf);
$pdf->renderPDF($rawpdf);
//$pdf->downloadPDF($rawpdf);
//echo $pdf->getMIMEAttachmentPDF($rawpdf);