David PHAM-VAN

Implement To be signed flieds

# Changelog
## 3.3.0
- Implement To be signed flieds
## 3.2.0
- Fix documentation
... ...
... ... @@ -417,9 +417,10 @@ class PdfAnnotSign extends PdfAnnotWidget {
@override
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
assert(page.pdfDocument.sign != null);
if (page.pdfDocument.sign != null) {
params['/V'] = page.pdfDocument.sign!.ref();
}
}
}
enum PdfFieldFlags {
... ...
... ... @@ -25,16 +25,17 @@ enum PdfSigFlags { signaturesExist, appendOnly }
class PdfSignature extends PdfObjectDict {
PdfSignature(
PdfDocument pdfDocument, {
required this.crypto,
Set<PdfSigFlags>? flags,
}) : flags = flags ?? const <PdfSigFlags>{PdfSigFlags.signaturesExist},
super(pdfDocument, type: '/Sig');
required this.value,
required this.flags,
}) : super(pdfDocument, type: '/Sig');
final Set<PdfSigFlags> flags;
final PdfSignatureBase crypto;
final PdfSignatureBase value;
int get flagsValue => flags
int get flagsValue => flags.isEmpty
? 0
: flags
.map<int>((PdfSigFlags e) => 1 >> e.index)
.reduce((int a, int b) => a | b);
... ... @@ -43,7 +44,7 @@ class PdfSignature extends PdfObjectDict {
@override
void write(PdfStream os) {
crypto.preSign(this, params);
value.preSign(this, params);
_offsetStart = os.offset + '$objser $objgen obj\n'.length;
super.write(os);
... ... @@ -54,7 +55,7 @@ class PdfSignature extends PdfObjectDict {
assert(_offsetStart != null && _offsetEnd != null,
'Must reserve the object space before signing the document');
await crypto.sign(this, os, params, _offsetStart, _offsetEnd);
await value.sign(this, os, params, _offsetStart, _offsetEnd);
}
}
... ...
... ... @@ -100,57 +100,6 @@ class AnnotationUrl extends AnnotationBuilder {
}
}
class AnnotationSignature extends AnnotationBuilder {
AnnotationSignature(
this.crypto, {
this.name,
this.signFlags,
this.border,
this.flags,
this.date,
this.color,
this.highlighting,
});
final Set<PdfSigFlags>? signFlags;
final PdfSignatureBase crypto;
final String? name;
final PdfBorder? border;
final Set<PdfAnnotFlags>? flags;
final DateTime? date;
final PdfColor? color;
final PdfAnnotHighlighting? highlighting;
@override
void build(Context context, PdfRect? box) {
context.document.sign ??= PdfSignature(
context.document,
crypto: crypto,
flags: signFlags,
);
PdfAnnot(
context.page,
PdfAnnotSign(
rect: context.localToGlobal(box!),
fieldName: name,
border: border,
flags: flags,
date: date,
color: color,
highlighting: highlighting,
),
);
}
}
class AnnotationTextField extends AnnotationBuilder {
AnnotationTextField({
this.name,
... ... @@ -259,31 +208,6 @@ class UrlLink extends Annotation {
}) : super(child: child, builder: AnnotationUrl(destination));
}
class Signature extends Annotation {
Signature({
required Widget child,
required PdfSignatureBase crypto,
required String name,
Set<PdfSigFlags>? signFlags,
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
PdfAnnotHighlighting? highlighting,
}) : super(
child: child,
builder: AnnotationSignature(
crypto,
signFlags: signFlags,
name: name,
border: border,
flags: flags,
date: date,
color: color,
highlighting: highlighting,
));
}
class Outline extends Anchor {
Outline({
Widget? child,
... ...
... ... @@ -307,3 +307,94 @@ class TextField extends StatelessWidget {
PdfAnnot(context.page, tf);
}
}
class Signature extends SingleChildWidget {
Signature({
Widget? child,
@Deprecated('Use value instead') PdfSignatureBase? crypto,
PdfSignatureBase? value,
required this.name,
this.appendOnly = false,
this.border,
this.flags,
this.date,
this.color,
this.highlighting,
}) : value = value ?? crypto,
super(child: child);
/// Field name
final String name;
/// Digital signature
final PdfSignatureBase? value;
/// Append
final bool appendOnly;
final PdfBorder? border;
/// Flags for this field
final Set<PdfAnnotFlags>? flags;
/// Date metadata
final DateTime? date;
/// Field color
final PdfColor? color;
/// Field highlighting
final PdfAnnotHighlighting? highlighting;
@override
void paint(Context context) {
super.paint(context);
if (value != null) {
context.document.sign ??= PdfSignature(
context.document,
value: value!,
flags: {
PdfSigFlags.signaturesExist,
if (appendOnly) PdfSigFlags.appendOnly,
},
);
} else {
paintChild(context);
}
final bf = PdfAnnotSign(
rect: context.localToGlobal(box!),
fieldName: name,
border: border,
flags: flags,
date: date,
color: color,
highlighting: highlighting,
);
if (child != null && value != null) {
final mat = context.canvas.getTransform();
final translation = Vector3(0, 0, 0);
final rotation = Quaternion(0, 0, 0, 0);
final scale = Vector3(0, 0, 0);
mat
..decompose(translation, rotation, scale)
..leftTranslate(-translation.x, -translation.y)
..translate(box!.x, box!.y);
final canvas = bf.appearance(context.document, PdfAnnotAppearance.normal,
matrix: mat);
Widget.draw(
child!,
offset: PdfPoint.zero,
canvas: canvas,
page: context.page,
constraints:
BoxConstraints.tightFor(width: box!.width, height: box!.height),
);
}
PdfAnnot(context.page, bf);
}
}
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 3.2.0
version: 3.3.0
environment:
sdk: ">=2.12.0-0 <3.0.0"
... ...