David PHAM-VAN

Add encryption support

## 1.3.14
* Add Document ID
* Add encryption support
## 1.3.13
... ...
... ... @@ -35,6 +35,7 @@ part 'src/color.dart';
part 'src/colors.dart';
part 'src/compatibility.dart';
part 'src/document.dart';
part 'src/encryption.dart';
part 'src/font_descriptor.dart';
part 'src/font_metrics.dart';
part 'src/font.dart';
... ...
... ... @@ -86,6 +86,9 @@ class PdfDocument {
/// No compression by default
final DeflateCallback deflate;
/// Object used to encrypt the document
PdfEncryption encryption;
/// These map the page modes just defined to the pagemodes setting of Pdf.
static const List<String> _PdfPageModes = <String>[
'/UseNone',
... ...
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
part of pdf;
abstract class PdfEncryption extends PdfObject {
PdfEncryption(PdfDocument pdfDocument) : super(pdfDocument, null);
List<int> encrypt(List<int> input, PdfObject object);
}
... ...
... ... @@ -54,6 +54,9 @@ class PdfObjectStream extends PdfObject {
// This is a non-deflated stream
_data = buf.output();
}
if (pdfDocument.encryption != null) {
_data = pdfDocument.encryption.encrypt(_data, this);
}
params['/Length'] = PdfStream.intNum(_data.length);
}
... ...
... ... @@ -37,6 +37,9 @@ class PdfOutput {
/// This is used to track the /Info object (info)
PdfObject infoID;
/// This is used to track the /Encrypt object (encryption)
PdfEncryption encryptID;
/// This method writes a [PdfObject] to the stream.
///
/// @param ob [PdfObject] Object to write
... ... @@ -49,6 +52,9 @@ class PdfOutput {
if (ob is PdfInfo) {
infoID = ob;
}
if (ob is PdfEncryption) {
encryptID = ob;
}
offsets.add(PdfXref(ob.objser, os.offset));
ob._write(os);
... ... @@ -117,6 +123,11 @@ class PdfOutput {
params['/Info'] = infoID.ref();
}
// the /Encrypt reference (OPTIONAL)
if (encryptID != null) {
params['/Encrypt'] = encryptID.ref();
}
// end the trailer object
os.putDictionary(params);
os.putString('\nstartxref\n$xref\n%%EOF\n');
... ...