Subversion Repositories Applications.annuaire

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_016.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-10-19
6
//
7
// Description : Example 016 for TCPDF class
8
//               Document Encryption / Security
9
//
10
// Author: Nicola Asuni
11
//
12
// (c) Copyright:
13
//               Nicola Asuni
14
//               Tecnick.com s.r.l.
15
//               Via Della Pace, 11
16
//               09044 Quartucciu (CA)
17
//               ITALY
18
//               www.tecnick.com
19
//               info@tecnick.com
20
//============================================================+
21
 
22
/**
23
 * Creates an example PDF TEST document using TCPDF
24
 * @package com.tecnick.tcpdf
25
 * @abstract TCPDF - Example: Document Encryption / Security
26
 * @author Nicola Asuni
27
 * @copyright 2004-2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
28
 * @link http://tcpdf.org
29
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
30
 * @since 2008-03-04
31
 */
32
 
33
require_once('../config/lang/eng.php');
34
require_once('../tcpdf.php');
35
 
36
// create new PDF document
37
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
38
 
39
 
40
// *** Set PDF protection (encryption) *********************
41
 
42
/*
43
  The permission array is composed of values taken from the following ones (specify the ones you want to block):
44
	- print : Print the document;
45
	- modify : Modify the contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble';
46
	- copy : Copy or otherwise extract text and graphics from the document;
47
	- annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields);
48
	- fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified;
49
	- extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes);
50
	- assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set;
51
	- print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality.
52
	- owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions.
53
 
54
 If you don't set any password, the document will open as usual.
55
 If you set a user password, the PDF viewer will ask for it before displaying the document.
56
 The master (owner) password, if different from the user one, can be used to get full document access.
57
 
58
 Possible encryption modes are:
59
 
60
 	1 = RSA 128 bit
61
 	2 = AES 128 bit
62
 	3 = AES 256 bit
63
 
64
 NOTES:
65
 - To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt
66
 - To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12
67
 - To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes
68
 
69
*/
70
 
71
$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);
72
 
73
// Example with public-key
74
// To open the document you need to install the private key (tcpdf.p12) on the Acrobat Reader. The password is: 1234
75
//$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=1, $pubkeys=array(array('c' => 'file://../tcpdf.crt', 'p' => array('print'))));
76
 
77
// *********************************************************
78
 
79
 
80
// set document information
81
$pdf->SetCreator(PDF_CREATOR);
82
$pdf->SetAuthor('Nicola Asuni');
83
$pdf->SetTitle('TCPDF Example 016');
84
$pdf->SetSubject('TCPDF Tutorial');
85
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
86
 
87
// set default header data
88
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 016', PDF_HEADER_STRING);
89
 
90
// set header and footer fonts
91
$pdf->setHeaderFont(Array('helvetica', '', PDF_FONT_SIZE_MAIN));
92
$pdf->setFooterFont(Array('helvetica', '', PDF_FONT_SIZE_DATA));
93
 
94
// set default monospaced font
95
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
96
 
97
//set margins
98
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
99
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
100
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
101
 
102
//set auto page breaks
103
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
104
 
105
//set image scale factor
106
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
107
 
108
//set some language-dependent strings
109
$pdf->setLanguageArray($l);
110
 
111
// ---------------------------------------------------------
112
 
113
// set font
114
$pdf->SetFont('times', '', 16);
115
 
116
// add a page
117
$pdf->AddPage();
118
 
119
// set some text to print
120
$txt = <<<EOD
121
Encryption Example
122
 
123
Consult the source code documentation for the SetProtection() method.
124
EOD;
125
 
126
// print a block of text using Write()
127
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
128
 
129
 
130
// ---------------------------------------------------------
131
 
132
//Close and output PDF document
133
$pdf->Output('example_016.pdf', 'I');
134
 
135
//============================================================+
136
// END OF FILE
137
//============================================================+