On this page
Add Text Watermark
To add a text watermark, follow these steps:
- Use
CPDFReaderWidget
to display the PDF document. - Set the required properties for the text watermark using
CPDFReaderWidgetController
, including content, font, color, and size. - Configure general watermark properties.
Here’s an example of how to create a text watermark:
dart
late CPDFReaderWidgetController _controller;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(),
body: Column(children: [
TextButton(onPressed: () async{
await _controller.document.createWatermark(CPDFWatermark.text(
textContent: 'ComPDFKit',
scale: 1.0,
fontSize: 60,
rotation: 0,
horizontalAlignment: CPDFWatermarkHorizontalAlignment.center,
verticalAlignment: CPDFWatermarkVerticalAlignment.center,
textColor: Colors.red,
pages: [0, 1, 2, 3]));
}, child: const Text('Add Text Watermark')),
Expanded(child: CPDFReaderWidget(
document: widget.documentPath,
configuration: CPDFConfiguration(),
onCreated: (controller) {
setState(() {
_controller = controller;
});
},
))
],));
}