John Harris
Committed by David PHAM-VAN

Add more annotations

# Changelog
## 3.5.0
- Add annotations [John Harris]
## 3.4.2
- Revert dart format
... ...
... ... @@ -99,6 +99,8 @@ abstract class PdfAnnotBase {
this.flags,
this.date,
this.color,
this.subject,
this.author,
});
/// The subtype of the outline, ie text, note, etc
... ... @@ -115,6 +117,12 @@ abstract class PdfAnnotBase {
/// The internal name for a link
final String? name;
/// The author of the annotation
final String? author;
/// The subject of the annotation
final String? subject;
/// Flags specifying various characteristics of the annotation
final Set<PdfAnnotFlags>? flags;
... ... @@ -223,6 +231,14 @@ abstract class PdfAnnotBase {
params['/C'] = PdfColorType(color!);
}
if (subject != null) {
params['/Subj'] = PdfSecString.fromString(object, subject!);
}
if (author != null) {
params['/T'] = PdfSecString.fromString(object, author!);
}
if (_appearances.isNotEmpty) {
params['/AP'] = PdfDict(_appearances);
if (_as != null) {
... ... @@ -242,6 +258,8 @@ class PdfAnnotText extends PdfAnnotBase {
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
String? subject,
String? author,
}) : super(
subtype: '/Text',
rect: rect,
... ... @@ -251,6 +269,8 @@ class PdfAnnotText extends PdfAnnotBase {
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
}
... ... @@ -263,6 +283,8 @@ class PdfAnnotNamedLink extends PdfAnnotBase {
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
String? subject,
String? author,
}) : super(
subtype: '/Link',
rect: rect,
... ... @@ -270,6 +292,8 @@ class PdfAnnotNamedLink extends PdfAnnotBase {
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final String dest;
... ... @@ -295,6 +319,8 @@ class PdfAnnotUrlLink extends PdfAnnotBase {
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
String? subject,
String? author,
}) : super(
subtype: '/Link',
rect: rect,
... ... @@ -302,6 +328,8 @@ class PdfAnnotUrlLink extends PdfAnnotBase {
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final String url;
... ... @@ -318,6 +346,177 @@ class PdfAnnotUrlLink extends PdfAnnotBase {
}
}
class PdfAnnotSquare extends PdfAnnotBase {
/// Create an Square annotation
PdfAnnotSquare({
required PdfRect rect,
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
this.interiorColor,
String? subject,
String? author,
}) : super(
subtype: '/Square',
rect: rect,
border: border,
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final PdfColor? interiorColor;
@override
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
if (interiorColor != null) {
params['/IC'] = PdfColorType(interiorColor!);
}
}
}
class PdfAnnotCircle extends PdfAnnotBase {
/// Create an Circle annotation
PdfAnnotCircle({
required PdfRect rect,
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
this.interiorColor,
String? subject,
String? author,
}) : super(
subtype: '/Circle',
rect: rect,
border: border,
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final PdfColor? interiorColor;
@override
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
if (interiorColor != null) {
params['/IC'] = PdfColorType(interiorColor!);
}
}
}
class PdfAnnotPolygon extends PdfAnnotBase {
/// Create an Polygon annotation
PdfAnnotPolygon(this.document, this.points,
{required PdfRect rect,
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
this.interiorColor,
String? subject,
String? author,
bool closed = true})
: super(
subtype: closed ? '/PolyLine' : '/Polygon',
rect: rect,
border: border,
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final PdfDocument document;
final List<PdfPoint> points;
final PdfColor? interiorColor;
@override
void build(PdfPage page, PdfObject object, PdfDict params) {
super.build(page, object, params);
// Flip the points on the Y axis.
final flippedPoints =
points.map((e) => PdfPoint(e.x, rect.height - e.y)).toList();
final verticies = <num>[];
for (var i = 0; i < flippedPoints.length; i++) {
verticies.add(flippedPoints[i].x);
verticies.add(flippedPoints[i].y);
}
params['/Vertices'] = PdfArray.fromNum(verticies);
if (interiorColor != null) {
params['/IC'] = PdfColorType(interiorColor!);
}
}
}
class PdfAnnotInk extends PdfAnnotBase {
/// Create an Ink List annotation
PdfAnnotInk(
this.document,
this.points, {
required PdfRect rect,
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
PdfColor? color,
String? subject,
String? author,
String? content,
}) : super(
subtype: '/Ink',
rect: rect,
border: border,
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
content: content,
);
final PdfDocument document;
final List<List<PdfPoint>> points;
@override
void build(
PdfPage page,
PdfObject object,
PdfDict params,
) {
super.build(page, object, params);
final verticies = List<List<num>>.filled(points.length, <num>[]);
for (var listIndex = 0; listIndex < points.length; listIndex++) {
// Flip the points on the Y axis.
final flippedPoints = points[listIndex]
.map((e) => PdfPoint(e.x, rect.height - e.y))
.toList();
for (var i = 0; i < flippedPoints.length; i++) {
verticies[listIndex].add(flippedPoints[i].x);
verticies[listIndex].add(flippedPoints[i].y);
}
}
params['/InkList'] =
PdfArray(verticies.map((v) => PdfArray.fromNum(v)).toList());
}
}
enum PdfAnnotHighlighting { none, invert, outline, push, toggle }
abstract class PdfAnnotWidget extends PdfAnnotBase {
... ... @@ -332,6 +531,8 @@ abstract class PdfAnnotWidget extends PdfAnnotBase {
PdfColor? color,
this.backgroundColor,
this.highlighting,
String? subject,
String? author,
}) : super(
subtype: '/Widget',
rect: rect,
... ... @@ -339,6 +540,8 @@ abstract class PdfAnnotWidget extends PdfAnnotBase {
flags: flags,
date: date,
color: color,
subject: subject,
author: author,
);
final String fieldType;
... ... @@ -531,6 +734,8 @@ class PdfFormField extends PdfAnnotWidget {
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
String? subject,
String? author,
PdfColor? color,
PdfColor? backgroundColor,
PdfAnnotHighlighting? highlighting,
... ... @@ -542,6 +747,8 @@ class PdfFormField extends PdfAnnotWidget {
border: border,
flags: flags,
date: date,
subject: subject,
author: author,
backgroundColor: backgroundColor,
color: color,
highlighting: highlighting,
... ... @@ -588,6 +795,8 @@ class PdfTextField extends PdfFormField {
PdfBorder? border,
Set<PdfAnnotFlags>? flags,
DateTime? date,
String? subject,
String? author,
PdfColor? color,
PdfColor? backgroundColor,
PdfAnnotHighlighting? highlighting,
... ... @@ -606,6 +815,8 @@ class PdfTextField extends PdfFormField {
border: border,
flags: flags,
date: date,
subject: subject,
author: author,
color: color,
backgroundColor: backgroundColor,
highlighting: highlighting,
... ...
... ... @@ -57,4 +57,13 @@ class PdfRect {
PdfPoint get topRight => PdfPoint(right, y);
PdfPoint get bottomLeft => PdfPoint(x, top);
PdfPoint get bottomRight => PdfPoint(right, top);
/// Returns a new rectangle with edges moved outwards by the given delta.
PdfRect inflate(double delta) {
return PdfRect.fromLTRB(
left - delta, top - delta, right + delta, bottom + delta);
}
/// Returns a new rectangle with edges moved inwards by the given delta.
PdfRect deflate(double delta) => inflate(-delta);
}
... ...
... ... @@ -14,10 +14,13 @@
* limitations under the License.
*/
import 'dart:math';
import 'package:pdf/pdf.dart';
import 'package:vector_math/vector_math_64.dart';
import 'geometry.dart';
import 'shape.dart';
import 'text_style.dart';
import 'theme.dart';
import 'widget.dart';
... ... @@ -63,7 +66,7 @@ class Anchor extends SingleChildWidget {
}
abstract class AnnotationBuilder {
void build(Context context, PdfRect? box);
PdfAnnot build(Context context, PdfRect? box);
}
class AnnotationLink extends AnnotationBuilder {
... ... @@ -72,8 +75,8 @@ class AnnotationLink extends AnnotationBuilder {
final String destination;
@override
void build(Context context, PdfRect? box) {
PdfAnnot(
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
context.page,
PdfAnnotNamedLink(
rect: context.localToGlobal(box!),
... ... @@ -84,28 +87,244 @@ class AnnotationLink extends AnnotationBuilder {
}
class AnnotationUrl extends AnnotationBuilder {
AnnotationUrl(this.destination);
AnnotationUrl(
this.destination, {
this.date,
this.subject,
this.author,
});
final String destination;
final DateTime? date;
final String? author;
final String? subject;
@override
void build(Context context, PdfRect? box) {
PdfAnnot(
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
context.page,
PdfAnnotUrlLink(
rect: context.localToGlobal(box!),
url: destination,
date: date,
author: author,
subject: subject,
),
);
}
}
class AnnotationSquare extends AnnotationBuilder {
AnnotationSquare({
this.color,
this.interiorColor,
this.border,
this.author,
this.date,
this.subject,
this.content,
});
final PdfColor? color;
final PdfColor? interiorColor;
final PdfBorder? border;
final String? author;
final DateTime? date;
final String? subject;
final String? content;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
context.page,
PdfAnnotSquare(
rect: context.localToGlobal(box!),
border: border,
color: color,
interiorColor: interiorColor,
date: date,
author: author,
subject: subject,
),
);
}
}
class AnnotationCircle extends AnnotationBuilder {
AnnotationCircle({
this.color,
this.interiorColor,
this.border,
this.author,
this.date,
this.subject,
this.content,
});
final PdfColor? color;
final PdfColor? interiorColor;
final PdfBorder? border;
final String? author;
final DateTime? date;
final String? subject;
final String? content;
@override
PdfAnnot build(Context context, PdfRect? box) {
return PdfAnnot(
context.page,
PdfAnnotCircle(
rect: context.localToGlobal(box!),
border: border,
color: color,
interiorColor: interiorColor,
date: date,
author: author,
subject: subject,
),
);
}
}
class AnnotationPolygon extends AnnotationBuilder {
AnnotationPolygon(
this.points, {
this.color,
this.interiorColor,
this.border,
this.author,
this.date,
this.subject,
this.content,
});
final List<PdfPoint> points;
final PdfColor? color;
final PdfColor? interiorColor;
final PdfBorder? border;
final String? author;
final DateTime? date;
final String? subject;
final String? content;
@override
PdfAnnot build(Context context, PdfRect? box) {
final globalPoints =
points.map((e) => context.localToGlobalPoint(e)).toList();
final rect = context.localToGlobal(PdfRect(
points.map((point) => point.x).reduce(min),
points.map((point) => point.y).reduce(min),
points.map((point) => point.x).reduce(max) -
points.map((point) => point.x).reduce(min),
points.map((point) => point.y).reduce(max) -
points.map((point) => point.y).reduce(min)));
final pdfAnnotPolygon = PdfAnnotPolygon(
context.document,
globalPoints,
rect: rect,
border: border,
color: color,
interiorColor: interiorColor,
date: date,
author: author,
subject: subject,
);
return PdfAnnot(context.page, pdfAnnotPolygon);
}
}
class AnnotationInk extends AnnotationBuilder {
AnnotationInk(
this.points, {
this.color,
this.border,
this.author,
this.date,
this.subject,
this.content,
});
final List<List<PdfPoint>> points;
final PdfColor? color;
final PdfBorder? border;
final String? author;
final DateTime? date;
final String? subject;
final String? content;
@override
PdfAnnot build(Context context, PdfRect? box) {
final globalPoints = points
.map((pList) => pList
.map((e) => context.localToGlobalPoint(e))
.toList(growable: false))
.toList(growable: false);
final allPoints =
points.expand((pointList) => pointList).toList(growable: false);
final minX = allPoints.map((point) => point.x).reduce(min);
final minY = allPoints.map((point) => point.y).reduce(min);
final maxX = allPoints.map((point) => point.x).reduce(max);
final maxY = allPoints.map((point) => point.y).reduce(max);
final rect =
context.localToGlobal(PdfRect(minX, minY, maxX - minX, maxY - minY));
final pdfAnnotInk = PdfAnnotInk(
context.document,
globalPoints,
rect: rect,
border: border,
color: color,
date: date,
author: author,
subject: subject,
content: content,
);
return PdfAnnot(context.page, pdfAnnotInk);
}
}
class AnnotationTextField extends AnnotationBuilder {
AnnotationTextField({
this.name,
this.border,
this.flags,
this.date,
this.subject,
this.author,
this.color,
this.backgroundColor,
this.highlighting,
... ... @@ -146,11 +365,15 @@ class AnnotationTextField extends AnnotationBuilder {
final Set<PdfFieldFlags>? fieldFlags;
final String? author;
final String? subject;
@override
void build(Context context, PdfRect? box) {
PdfAnnot build(Context context, PdfRect? box) {
final _textStyle = Theme.of(context).defaultTextStyle.merge(textStyle);
PdfAnnot(
return PdfAnnot(
context.page,
PdfTextField(
rect: context.localToGlobal(box!),
... ... @@ -158,6 +381,8 @@ class AnnotationTextField extends AnnotationBuilder {
border: border,
flags: flags,
date: date,
author: author,
subject: subject,
color: color,
backgroundColor: backgroundColor,
highlighting: highlighting,
... ... @@ -208,6 +433,148 @@ class UrlLink extends Annotation {
}) : super(child: child, builder: AnnotationUrl(destination));
}
class SquareAnnotation extends Annotation {
SquareAnnotation({
Widget? child,
PdfColor? color,
PdfColor? interiorColor,
PdfBorder? border,
String? author,
DateTime? date,
String? subject,
String? content,
}) : super(
child: child ??
Rectangle(
fillColor: interiorColor,
strokeWidth: border?.width ?? 1.0,
strokeColor: color),
builder: AnnotationSquare(
color: color,
interiorColor: interiorColor,
border: border,
author: author,
date: date,
content: content,
subject: subject,
),
);
}
class CircleAnnotation extends Annotation {
CircleAnnotation({
Widget? child,
PdfColor? color,
PdfColor? interiorColor,
PdfBorder? border,
String? author,
DateTime? date,
String? subject,
String? content,
}) : super(
child: child ??
Circle(
fillColor: interiorColor,
strokeWidth: border?.width ?? 1.0,
strokeColor: color),
builder: AnnotationCircle(
color: color,
interiorColor: interiorColor,
border: border,
author: author,
date: date,
content: content,
subject: subject,
),
);
}
class PolygonAnnotation extends Annotation {
PolygonAnnotation({
required List<PdfPoint> points,
Widget? child,
PdfColor? color,
PdfColor? interiorColor,
PdfBorder? border,
String? author,
DateTime? date,
String? subject,
String? content,
}) : super(
child: child ??
Polygon(
points: points,
strokeColor: color,
fillColor: interiorColor,
strokeWidth: border?.width ?? 1.0),
builder: AnnotationPolygon(
points,
color: color,
interiorColor: interiorColor,
border: border,
author: author,
date: date,
content: content,
subject: subject,
),
);
}
class PolyLineAnnotation extends Annotation {
PolyLineAnnotation({
required List<PdfPoint> points,
PdfColor? color,
PdfBorder? border,
String? author,
DateTime? date,
String? content,
String? subject,
}) : super(
child: Polygon(
points: points,
strokeColor: color,
close: false,
strokeWidth: border?.width ?? 1.0),
builder: AnnotationPolygon(
points,
color: color,
border: border,
author: author,
date: date,
content: content,
subject: subject,
),
);
}
class InkAnnotation extends Annotation {
InkAnnotation({
required List<List<PdfPoint>> points,
Widget? child,
PdfColor? color,
PdfBorder? border,
String? author,
DateTime? date,
String? content,
String? subject,
}) : super(
child: child ??
InkList(
points: points,
strokeColor: color,
strokeWidth: border?.width ?? 1.0),
builder: AnnotationInk(
points,
color: color,
border: border,
author: author,
date: date,
content: content,
subject: subject,
),
);
}
class Outline extends Anchor {
Outline({
Widget? child,
... ...
/*
* 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.
*/
import 'package:pdf/src/pdf/point.dart';
import 'package:pdf/src/widgets/geometry.dart';
import 'package:pdf/src/widgets/widget.dart';
import '../../pdf.dart';
class Circle extends Widget {
Circle({this.fillColor, this.strokeColor, this.strokeWidth = 1.0});
final PdfColor? fillColor;
final PdfColor? strokeColor;
final double strokeWidth;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
}
@override
void paint(Context context) {
super.paint(context);
final canvas = context.canvas;
canvas.saveContext();
if (fillColor != null) {
canvas.setFillColor(fillColor!);
}
if (strokeColor != null) {
canvas.setStrokeColor(strokeColor);
}
canvas.setLineWidth(strokeWidth);
canvas.drawEllipse(
box!.width / 2, box!.height / 2, box!.width / 2, box!.height / 2);
if (strokeColor != null && fillColor != null) {
canvas.fillAndStrokePath();
} else if (strokeColor != null) {
canvas.strokePath();
} else {
canvas.fillPath();
}
canvas.restoreContext();
}
}
class Rectangle extends Widget {
Rectangle({this.fillColor, this.strokeColor, this.strokeWidth = 1.0});
final PdfColor? fillColor;
final PdfColor? strokeColor;
final double strokeWidth;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
}
@override
void paint(Context context) {
super.paint(context);
final canvas = context.canvas;
canvas.saveContext();
if (fillColor != null) {
canvas.setFillColor(fillColor!);
}
if (strokeColor != null) {
canvas.setStrokeColor(strokeColor);
}
canvas.setLineWidth(strokeWidth);
canvas.drawRect(0, 0, box!.width, box!.height);
if (strokeColor != null && fillColor != null) {
canvas.fillAndStrokePath();
} else if (strokeColor != null) {
canvas.strokePath();
} else {
canvas.fillPath();
}
canvas.restoreContext();
}
}
class Polygon extends Widget {
Polygon(
{required this.points,
this.fillColor,
this.strokeColor,
this.strokeWidth = 1.0,
this.close = true});
final List<PdfPoint> points;
final PdfColor? fillColor;
final PdfColor? strokeColor;
final double strokeWidth;
final bool close;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
}
@override
void paint(Context context) {
super.paint(context);
// Make sure there are enough points to draw anything
if (points.length < 3) {
return;
}
final canvas = context.canvas;
canvas.saveContext();
if (fillColor != null) {
canvas.setFillColor(fillColor!);
}
if (strokeColor != null) {
canvas.setStrokeColor(strokeColor);
}
canvas.setLineWidth(strokeWidth);
// Flip the points on the Y axis.
final flippedPoints =
points.map((e) => PdfPoint(e.x, box!.height - e.y)).toList();
canvas.moveTo(flippedPoints[0].x, flippedPoints[0].y);
for (var i = 0; i < flippedPoints.length; i++) {
canvas.lineTo(flippedPoints[i].x, flippedPoints[i].y);
}
if (close) {
canvas.closePath();
}
if (strokeColor != null && fillColor != null) {
canvas.fillAndStrokePath();
} else if (strokeColor != null) {
canvas.strokePath();
} else {
canvas.fillPath();
}
canvas.restoreContext();
}
}
class InkList extends Widget {
InkList({required this.points, this.strokeColor, this.strokeWidth = 1.0});
final List<List<PdfPoint>> points;
final PdfColor? strokeColor;
final double strokeWidth;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
}
@override
void paint(Context context) {
super.paint(context);
final canvas = context.canvas;
canvas.saveContext();
if (strokeColor != null) {
canvas.setStrokeColor(strokeColor);
}
canvas.setLineWidth(strokeWidth);
// Flip the points on the Y axis.
for (var subLineIndex = 0; subLineIndex < points.length; subLineIndex++) {
final flippedPoints = points[subLineIndex]
.map((e) => PdfPoint(e.x, box!.height - e.y))
.toList();
canvas.moveTo(flippedPoints[0].x, flippedPoints[0].y);
for (var i = 0; i < flippedPoints.length; i++) {
canvas.lineTo(flippedPoints[i].x, flippedPoints[i].y);
}
}
canvas.strokePath();
canvas.restoreContext();
}
}
... ...
... ... @@ -112,6 +112,12 @@ class Context {
y.reduce(math.max),
);
}
PdfPoint localToGlobalPoint(PdfPoint point) {
final mat = canvas.getTransform();
final xy = mat.transform3(Vector3(point.x, point.y, 0));
return PdfPoint(xy.x, xy.y);
}
}
class Inherited {
... ...
... ... @@ -49,6 +49,7 @@ export 'src/widgets/page_theme.dart';
export 'src/widgets/partitions.dart';
export 'src/widgets/placeholders.dart';
export 'src/widgets/progress.dart';
export 'src/widgets/shape.dart';
export 'src/widgets/stack.dart';
export 'src/widgets/svg.dart';
export 'src/widgets/table.dart';
... ...
... ... @@ -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.4.2
version: 3.5.0
environment:
sdk: ">=2.12.0 <3.0.0"
... ...
... ... @@ -17,59 +17,103 @@
import 'dart:io';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
import 'package:test/test.dart';
void main() {
test('Pdf Annotations', () async {
final pdf = PdfDocument();
final page = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300));
final page1 = PdfPage(pdf, pageFormat: const PdfPageFormat(500, 300));
pdf.pdfNames.addDest('target', page1, posY: 100);
final g = page.getGraphics();
late Document pdf;
PdfAnnot(
page,
PdfAnnotText(
rect: const PdfRect(100, 100, 50, 50),
content: 'Hello',
),
);
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
PdfAnnot(
page,
PdfAnnotNamedLink(
dest: 'target',
rect: const PdfRect(100, 150, 50, 50),
test('Pdf Link Annotations', () async {
pdf.addPage(
Page(
build: (context) => Column(
children: [
Link(child: Text('A link'), destination: 'destination'),
UrlLink(
child: Text('GitHub'),
destination: 'https://github.com/DavBfr/dart_pdf/'),
],
),
),
);
g.drawRect(100, 150, 50, 50);
g.strokePath();
});
PdfAnnot(
page,
PdfAnnotUrlLink(
rect: const PdfRect(100, 250, 50, 50),
url: 'https://github.com/DavBfr/dart_pdf/',
test('Pdf Shape Annotations', () async {
pdf.addPage(
Page(
build: (context) => Wrap(
spacing: 20,
runSpacing: 20,
children: [
SizedBox(
width: 200,
height: 200,
child: CircleAnnotation(
color: PdfColors.blue,
author: 'David PHAM-VAN',
),
),
SizedBox(
width: 200,
height: 200,
child: SquareAnnotation(
color: PdfColors.red,
),
),
SizedBox(
width: 200,
height: 100,
child: PolyLineAnnotation(
points: const [
PdfPoint(10, 10),
PdfPoint(10, 30),
PdfPoint(50, 70)
],
color: PdfColors.purple,
),
),
SizedBox(
width: 200,
height: 100,
child: PolygonAnnotation(
points: const [
PdfPoint(10, 10),
PdfPoint(10, 30),
PdfPoint(50, 70)
],
color: PdfColors.orange,
),
),
SizedBox(
width: 200,
height: 100,
child: InkAnnotation(
points: const [
[PdfPoint(10, 10), PdfPoint(10, 30), PdfPoint(50, 70)],
[PdfPoint(100, 10), PdfPoint(100, 30), PdfPoint(150, 70)],
],
color: PdfColors.green,
),
),
],
),
),
);
g.drawRect(100, 250, 50, 50);
g.strokePath();
});
PdfAnnot(
page,
PdfTextField(
rect: const PdfRect(100, 50, 50, 20),
fieldName: 'test',
font: PdfFont.helvetica(pdf),
fontSize: 10,
textColor: PdfColors.blue,
),
);
// g.drawRect(100, 50, 50, 20);
g.strokePath();
test('Pdf Anchor Annotation', () async {
pdf.addPage(Page(
build: (context) =>
Anchor(child: Text('The destination'), name: 'destination'),
));
});
tearDownAll(() async {
final file = File('annotations.pdf');
await file.writeAsBytes(await pdf.save());
});
... ...