Showing
6 changed files
with
42 additions
and
0 deletions
@@ -35,6 +35,7 @@ part 'src/color.dart'; | @@ -35,6 +35,7 @@ part 'src/color.dart'; | ||
35 | part 'src/colors.dart'; | 35 | part 'src/colors.dart'; |
36 | part 'src/compatibility.dart'; | 36 | part 'src/compatibility.dart'; |
37 | part 'src/document.dart'; | 37 | part 'src/document.dart'; |
38 | +part 'src/encryption.dart'; | ||
38 | part 'src/font_descriptor.dart'; | 39 | part 'src/font_descriptor.dart'; |
39 | part 'src/font_metrics.dart'; | 40 | part 'src/font_metrics.dart'; |
40 | part 'src/font.dart'; | 41 | part 'src/font.dart'; |
@@ -86,6 +86,9 @@ class PdfDocument { | @@ -86,6 +86,9 @@ class PdfDocument { | ||
86 | /// No compression by default | 86 | /// No compression by default |
87 | final DeflateCallback deflate; | 87 | final DeflateCallback deflate; |
88 | 88 | ||
89 | + /// Object used to encrypt the document | ||
90 | + PdfEncryption encryption; | ||
91 | + | ||
89 | /// These map the page modes just defined to the pagemodes setting of Pdf. | 92 | /// These map the page modes just defined to the pagemodes setting of Pdf. |
90 | static const List<String> _PdfPageModes = <String>[ | 93 | static const List<String> _PdfPageModes = <String>[ |
91 | '/UseNone', | 94 | '/UseNone', |
pdf/lib/src/encryption.dart
0 → 100644
1 | +/* | ||
2 | + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the 'License'); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an 'AS IS' BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +part of pdf; | ||
18 | + | ||
19 | +abstract class PdfEncryption extends PdfObject { | ||
20 | + PdfEncryption(PdfDocument pdfDocument) : super(pdfDocument, null); | ||
21 | + | ||
22 | + List<int> encrypt(List<int> input, PdfObject object); | ||
23 | +} |
@@ -54,6 +54,9 @@ class PdfObjectStream extends PdfObject { | @@ -54,6 +54,9 @@ class PdfObjectStream extends PdfObject { | ||
54 | // This is a non-deflated stream | 54 | // This is a non-deflated stream |
55 | _data = buf.output(); | 55 | _data = buf.output(); |
56 | } | 56 | } |
57 | + if (pdfDocument.encryption != null) { | ||
58 | + _data = pdfDocument.encryption.encrypt(_data, this); | ||
59 | + } | ||
57 | params['/Length'] = PdfStream.intNum(_data.length); | 60 | params['/Length'] = PdfStream.intNum(_data.length); |
58 | } | 61 | } |
59 | 62 |
@@ -37,6 +37,9 @@ class PdfOutput { | @@ -37,6 +37,9 @@ class PdfOutput { | ||
37 | /// This is used to track the /Info object (info) | 37 | /// This is used to track the /Info object (info) |
38 | PdfObject infoID; | 38 | PdfObject infoID; |
39 | 39 | ||
40 | + /// This is used to track the /Encrypt object (encryption) | ||
41 | + PdfEncryption encryptID; | ||
42 | + | ||
40 | /// This method writes a [PdfObject] to the stream. | 43 | /// This method writes a [PdfObject] to the stream. |
41 | /// | 44 | /// |
42 | /// @param ob [PdfObject] Object to write | 45 | /// @param ob [PdfObject] Object to write |
@@ -49,6 +52,9 @@ class PdfOutput { | @@ -49,6 +52,9 @@ class PdfOutput { | ||
49 | if (ob is PdfInfo) { | 52 | if (ob is PdfInfo) { |
50 | infoID = ob; | 53 | infoID = ob; |
51 | } | 54 | } |
55 | + if (ob is PdfEncryption) { | ||
56 | + encryptID = ob; | ||
57 | + } | ||
52 | 58 | ||
53 | offsets.add(PdfXref(ob.objser, os.offset)); | 59 | offsets.add(PdfXref(ob.objser, os.offset)); |
54 | ob._write(os); | 60 | ob._write(os); |
@@ -117,6 +123,11 @@ class PdfOutput { | @@ -117,6 +123,11 @@ class PdfOutput { | ||
117 | params['/Info'] = infoID.ref(); | 123 | params['/Info'] = infoID.ref(); |
118 | } | 124 | } |
119 | 125 | ||
126 | + // the /Encrypt reference (OPTIONAL) | ||
127 | + if (encryptID != null) { | ||
128 | + params['/Encrypt'] = encryptID.ref(); | ||
129 | + } | ||
130 | + | ||
120 | // end the trailer object | 131 | // end the trailer object |
121 | os.putDictionary(params); | 132 | os.putDictionary(params); |
122 | os.putString('\nstartxref\n$xref\n%%EOF\n'); | 133 | os.putString('\nstartxref\n$xref\n%%EOF\n'); |
-
Please register or login to post a comment