123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873 |
- ///
- /// Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
- ///
- /// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
- /// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
- /// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
- /// This notice may not be removed from this file.
- ///
- import 'dart:convert';
- import 'package:compdfkit_flutter/util/extension/cpdf_color_extension.dart';
- import 'package:flutter/material.dart';
- import 'cpdf_options.dart';
- /// modeConfig: Configuration of parameters that can be adjusted when opening a PDF interface.
- /// For example, setting the default display mode when opening, such as entering viewer or annotations mode.
- ///
- /// toolbarConfig: Configuration of top toolbar functionality and menu feature lists.
- /// This allows you to customize the buttons and menu options on the top toolbar for various operations.
- ///
- /// readerViewConfig: Configuration related to the PDF view,
- /// including functions like highlighting hyperlinks and form field highlighting.
- ///
- /// ```dart
- /// ComPDFKit.openDocument(
- /// tempDocumentPath,
- /// password: '',
- /// configuration: CPDFConfiguration());
- ///
- /// ```
- class CPDFConfiguration {
- ModeConfig modeConfig;
- ToolbarConfig toolbarConfig;
- ReaderViewConfig readerViewConfig;
- CPDFAnnotationsConfig annotationsConfig;
- CPDFContentEditorConfig contentEditorConfig;
- CPDFFormsConfig formsConfig;
- CPDFGlobalConfig globalConfig;
- CPDFConfiguration(
- {this.modeConfig = const ModeConfig(initialViewMode: CPreviewMode.viewer),
- this.toolbarConfig = const ToolbarConfig(),
- this.readerViewConfig = const ReaderViewConfig(),
- this.annotationsConfig = const CPDFAnnotationsConfig(),
- this.contentEditorConfig = const CPDFContentEditorConfig(),
- this.formsConfig = const CPDFFormsConfig(),
- this.globalConfig = const CPDFGlobalConfig()});
- String toJson() => jsonEncode({
- 'modeConfig': modeConfig.toJson(),
- 'toolbarConfig': toolbarConfig.toJson(),
- 'readerViewConfig': readerViewConfig.toJson(),
- 'annotationsConfig': annotationsConfig.toJson(),
- 'contentEditorConfig': contentEditorConfig.toJson(),
- 'formsConfig': formsConfig.toJson(),
- 'global': globalConfig.toJson()
- });
- }
- class ModeConfig {
- final CPreviewMode initialViewMode;
- final List<CPreviewMode> availableViewModes;
- final bool readerOnly;
- const ModeConfig(
- {this.initialViewMode = CPreviewMode.viewer,
- this.readerOnly = false,
- this.availableViewModes = CPreviewMode.values});
- Map<String, dynamic> toJson() => {
- 'initialViewMode': initialViewMode.name,
- 'readerOnly': readerOnly,
- 'availableViewModes': availableViewModes.map((e) => e.name).toList()
- };
- }
- class ToolbarConfig {
- final List<ToolbarAction> androidAvailableActions;
- final List<ToolbarAction> iosLeftBarAvailableActions;
- final List<ToolbarAction> iosRightBarAvailableActions;
- final List<ToolbarMenuAction> availableMenus;
- const ToolbarConfig(
- {this.androidAvailableActions = const [
- ToolbarAction.thumbnail,
- ToolbarAction.search,
- ToolbarAction.bota,
- ToolbarAction.menu,
- ],
- this.iosLeftBarAvailableActions = const [
- ToolbarAction.back,
- ToolbarAction.thumbnail,
- ],
- this.iosRightBarAvailableActions = const [
- ToolbarAction.search,
- ToolbarAction.bota,
- ToolbarAction.menu
- ],
- this.availableMenus = const [
- ToolbarMenuAction.viewSettings,
- ToolbarMenuAction.documentEditor,
- ToolbarMenuAction.security,
- ToolbarMenuAction.watermark,
- ToolbarMenuAction.flattened,
- ToolbarMenuAction.documentInfo,
- ToolbarMenuAction.save,
- ToolbarMenuAction.share,
- ToolbarMenuAction.openDocument,
- ]});
- Map<String, dynamic> toJson() => {
- 'androidAvailableActions':
- androidAvailableActions.map((e) => e.name).toList(),
- 'iosLeftBarAvailableActions':
- iosLeftBarAvailableActions.map((e) => e.name).toList(),
- 'iosRightBarAvailableActions':
- iosRightBarAvailableActions.map((e) => e.name).toList(),
- 'availableMenus': availableMenus.map((e) => e.name).toList()
- };
- }
- /// pdf readerView configuration
- class ReaderViewConfig {
- // Highlight hyperlink annotations in pdf
- final bool linkHighlight;
- // Highlight hyperlink form field
- final bool formFieldHighlight;
- final CPDFDisplayMode displayMode;
- final bool continueMode;
- final bool verticalMode;
- final bool cropMode;
- final CPDFThemes themes;
- final bool enableSliderBar;
- final bool enablePageIndicator;
- final int pageSpacing;
- final double pageScale;
- /// only android platform
- final bool pageSameWidth;
- const ReaderViewConfig(
- {this.linkHighlight = true,
- this.formFieldHighlight = true,
- this.displayMode = CPDFDisplayMode.singlePage,
- this.continueMode = true,
- this.verticalMode = true,
- this.cropMode = false,
- this.themes = CPDFThemes.light,
- this.enableSliderBar = true,
- this.enablePageIndicator = true,
- this.pageSpacing = 10,
- this.pageScale = 1.0,
- this.pageSameWidth = true});
- Map<String, dynamic> toJson() => {
- 'linkHighlight': linkHighlight,
- 'formFieldHighlight': formFieldHighlight,
- 'displayMode': displayMode.name,
- 'continueMode': continueMode,
- 'verticalMode': verticalMode,
- 'cropMode': cropMode,
- 'themes': themes.name,
- 'enableSliderBar': enableSliderBar,
- 'enablePageIndicator': enablePageIndicator,
- 'pageSpacing': pageSpacing,
- 'pageScale': pageScale,
- 'pageSameWidth': pageSameWidth
- };
- }
- class CPDFAnnotationsConfig {
- final List<CPDFAnnotationType> availableTypes;
- final List<CPDFConfigTool> availableTools;
- final CPDFAnnotationAttribute initAttribute;
- const CPDFAnnotationsConfig(
- {this.availableTypes = CPDFAnnotationType.values,
- this.availableTools = CPDFConfigTool.values,
- this.initAttribute = const CPDFAnnotationAttribute()});
- Map<String, dynamic> toJson() => {
- 'availableTypes': availableTypes.map((e) => e.name).toList(),
- 'availableTools': availableTools.map((e) => e.name).toList(),
- 'initAttribute': initAttribute.toJson()
- };
- }
- class CPDFAnnotationAttribute {
- final CPDFAnnotAttr note;
- final CPDFAnnotAttr highlight;
- final CPDFAnnotAttr underline;
- final CPDFAnnotAttr squiggly;
- final CPDFAnnotAttr strikeout;
- final CPDFAnnotAttr ink;
- final CPDFAnnotAttr square;
- final CPDFAnnotAttr circle;
- final CPDFAnnotAttr line;
- final CPDFAnnotAttr arrow;
- final CPDFAnnotAttr freeText;
- const CPDFAnnotationAttribute({
- this.note = const CPDFAnnotAttr.note(),
- this.highlight = const CPDFAnnotAttr.highlight(),
- this.underline = const CPDFAnnotAttr.underline(),
- this.squiggly = const CPDFAnnotAttr.squiggly(),
- this.strikeout = const CPDFAnnotAttr.strikeout(),
- this.ink = const CPDFAnnotAttr.ink(),
- this.square = const CPDFAnnotAttr.square(),
- this.circle = const CPDFAnnotAttr.circle(),
- this.line = const CPDFAnnotAttr.line(),
- this.arrow = const CPDFAnnotAttr.arrow(),
- this.freeText = const CPDFAnnotAttr.freeText(),
- });
- Map<String, dynamic> toJson() => {
- 'note': note.toJson(),
- 'highlight': highlight.toJson(),
- 'underline': underline.toJson(),
- 'squiggly': squiggly.toJson(),
- 'strikeout': strikeout.toJson(),
- 'ink': ink.toJson(),
- 'square': square.toJson(),
- 'circle': circle.toJson(),
- 'line': line.toJson(),
- 'arrow': arrow.toJson(),
- 'freeText': freeText.toJson()
- };
- }
- class CPDFAnnotAttr {
- final CPDFAnnotationType? annotationType;
- final Color? color;
- final int? alpha;
- final int? borderWidth;
- final Color? fillColor;
- final Color? borderColor;
- final int? borderAlpha;
- final int? colorAlpha;
- final CPDFBorderStyle? borderStyle;
- final CPDFLineType? startLineType;
- final CPDFLineType? tailLineType;
- final Color? fontColor;
- final int? fontColorAlpha;
- final int? fontSize;
- final bool? isBold;
- final bool? isItalic;
- final CPDFAlignment? alignment;
- final CPDFTypeface? typeface;
- const CPDFAnnotAttr(
- {required this.annotationType,
- this.color,
- this.alpha,
- this.borderWidth,
- this.fillColor,
- this.borderColor,
- this.borderAlpha,
- this.colorAlpha,
- this.borderStyle,
- this.startLineType,
- this.tailLineType,
- this.fontColor,
- this.fontColorAlpha,
- this.fontSize,
- this.isBold,
- this.isItalic,
- this.alignment,
- this.typeface});
- const CPDFAnnotAttr.note(
- {Color color = const Color(0xFF1460F3), int alpha = 255})
- : this(
- annotationType: CPDFAnnotationType.note,
- color: color,
- alpha: alpha);
- const CPDFAnnotAttr.highlight(
- {Color color = const Color(0xFF1460F3), int alpha = 77})
- : this(
- annotationType: CPDFAnnotationType.highlight,
- color: color,
- alpha: alpha);
- const CPDFAnnotAttr.underline(
- {Color color = const Color(0xFF1460F3), int alpha = 77})
- : this(
- annotationType: CPDFAnnotationType.underline,
- color: color,
- alpha: alpha);
- const CPDFAnnotAttr.squiggly(
- {Color color = const Color(0xFF1460F3), int alpha = 77})
- : this(
- annotationType: CPDFAnnotationType.squiggly,
- color: color,
- alpha: alpha);
- const CPDFAnnotAttr.strikeout(
- {Color color = const Color(0xFF1460F3), int alpha = 77})
- : this(
- annotationType: CPDFAnnotationType.highlight,
- color: color,
- alpha: alpha);
- const CPDFAnnotAttr.ink(
- {Color color = const Color(0xFF1460F3),
- int alpha = 100,
- int borderWidth = 10})
- : this(
- annotationType: CPDFAnnotationType.ink,
- color: color,
- alpha: alpha,
- borderWidth: borderWidth);
- const CPDFAnnotAttr.square({
- Color fillColor = const Color(0xFF1460F3),
- Color borderColor = Colors.black,
- int colorAlpha = 128,
- int borderWidth = 2,
- CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
- }) : this(
- annotationType: CPDFAnnotationType.square,
- fillColor: fillColor,
- borderColor: borderColor,
- colorAlpha: colorAlpha,
- borderWidth: borderWidth,
- borderStyle: borderStyle);
- const CPDFAnnotAttr.circle({
- Color fillColor = const Color(0xFF1460F3),
- Color borderColor = Colors.black,
- int colorAlpha = 128,
- int borderWidth = 2,
- CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
- }) : this(
- annotationType: CPDFAnnotationType.circle,
- fillColor: fillColor,
- borderColor: borderColor,
- colorAlpha: colorAlpha,
- borderWidth: borderWidth,
- borderStyle: borderStyle);
- const CPDFAnnotAttr.line({
- Color borderColor = const Color(0xFF1460F3),
- int borderAlpha = 100,
- int borderWidth = 5,
- CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
- }) : this(
- annotationType: CPDFAnnotationType.line,
- borderColor: borderColor,
- borderAlpha: borderAlpha,
- borderWidth: borderWidth,
- borderStyle: borderStyle,
- startLineType: CPDFLineType.none,
- tailLineType: CPDFLineType.none);
- const CPDFAnnotAttr.arrow(
- {Color borderColor = const Color(0xFF1460F3),
- int borderAlpha = 100,
- int borderWidth = 5,
- CPDFBorderStyle borderStyle = const CPDFBorderStyle.solid(),
- CPDFLineType startLineType = CPDFLineType.none,
- CPDFLineType tailLineType = CPDFLineType.openArrow})
- : this(
- annotationType: CPDFAnnotationType.arrow,
- borderColor: borderColor,
- borderAlpha: borderAlpha,
- borderWidth: borderWidth,
- borderStyle: borderStyle,
- startLineType: startLineType,
- tailLineType: tailLineType);
- const CPDFAnnotAttr.freeText(
- {Color fontColor = Colors.black,
- int fontColorAlpha = 255,
- int fontSize = 30,
- bool isBold = false,
- bool isItalic = false,
- CPDFAlignment alignment = CPDFAlignment.left,
- CPDFTypeface typeface = CPDFTypeface.helvetica})
- : this(
- annotationType: CPDFAnnotationType.freetext,
- fontColor: fontColor,
- fontColorAlpha: fontColorAlpha,
- fontSize: fontSize,
- isBold: isBold,
- isItalic: isItalic,
- alignment: alignment,
- typeface: typeface);
- Map<String, dynamic> toJson() {
- switch (annotationType) {
- case CPDFAnnotationType.note:
- case CPDFAnnotationType.highlight:
- case CPDFAnnotationType.underline:
- case CPDFAnnotationType.squiggly:
- case CPDFAnnotationType.strikeout:
- return {'color': color?.toHex(), 'alpha': alpha};
- case CPDFAnnotationType.ink:
- return {
- 'color': color?.toHex(),
- 'alpha': alpha,
- 'borderWidth': borderWidth
- };
- case CPDFAnnotationType.square:
- case CPDFAnnotationType.circle:
- return {
- 'fillColor': fillColor?.toHex(),
- 'borderColor': borderColor?.toHex(),
- 'colorAlpha': colorAlpha,
- 'borderWidth': borderWidth,
- 'borderStyle': borderStyle?.toJson(),
- };
- case CPDFAnnotationType.line:
- case CPDFAnnotationType.arrow:
- return {
- 'borderColor': borderColor?.toHex(),
- 'borderAlpha': borderAlpha,
- 'borderWidth': borderWidth,
- 'borderStyle': borderStyle?.toJson(),
- 'startLineType': startLineType?.name,
- 'tailLineType': tailLineType?.name
- };
- case CPDFAnnotationType.freetext:
- return {
- 'fontColor': fontColor?.toHex(),
- 'fontColorAlpha': fontColorAlpha,
- 'fontSize': fontSize,
- 'isBold': isBold,
- 'isItalic': isItalic,
- 'alignment': alignment?.name,
- 'typeface': typeface?.getFontName(),
- };
- default:
- return {};
- }
- }
- }
- class CPDFBorderStyle {
- final CPDFAnnotBorderStyle style;
- final double dashGap;
- const CPDFBorderStyle(
- {this.style = CPDFAnnotBorderStyle.solid, this.dashGap = 8.0});
- const CPDFBorderStyle.solid()
- : style = CPDFAnnotBorderStyle.solid,
- dashGap = 0;
- const CPDFBorderStyle.dashed({this.dashGap = 9.0})
- : style = CPDFAnnotBorderStyle.dashed;
- Map<String, dynamic> toJson() => {'style': style.name, 'dashGap': dashGap};
- }
- class CPDFContentEditorConfig {
- final List<CPDFContentEditorType> availableTypes;
- final List<CPDFConfigTool> availableTools;
- final CPDFContentEditorAttribute initAttribute;
- const CPDFContentEditorConfig(
- {this.availableTypes = CPDFContentEditorType.values,
- this.availableTools = CPDFConfigTool.values,
- this.initAttribute = const CPDFContentEditorAttribute()});
- Map<String, dynamic> toJson() => {
- 'availableTypes': availableTypes.map((e) => e.name).toList(),
- 'availableTools': availableTools.map((e) => e.name).toList(),
- 'initAttribute': initAttribute.toJson()
- };
- }
- class CPDFContentEditorAttribute {
- final CPDFContentEditorAttr text;
- const CPDFContentEditorAttribute({this.text = const CPDFContentEditorAttr()});
- Map<String, dynamic> toJson() => {'text': text.toJson()};
- }
- class CPDFContentEditorAttr {
- final Color fontColor;
- final int fontColorAlpha;
- final int fontSize;
- final bool isBold;
- final bool isItalic;
- final CPDFTypeface typeface;
- final CPDFAlignment alignment;
- const CPDFContentEditorAttr(
- {this.fontColor = Colors.black,
- this.fontColorAlpha = 255,
- this.fontSize = 30,
- this.isBold = false,
- this.isItalic = false,
- this.typeface = CPDFTypeface.helvetica,
- this.alignment = CPDFAlignment.left});
- Map<String, dynamic> toJson() => {
- 'fontColor': fontColor.toHex(),
- 'fontColorAlpha': fontColorAlpha,
- 'fontSize': fontSize,
- 'isBold': isBold,
- 'isItalic': isItalic,
- 'typeface': typeface.getFontName(),
- 'alignment': alignment.name
- };
- }
- class CPDFFormsConfig {
- final List<CPDFFormType> availableTypes;
- final List<CPDFFormConfigTool> availableTools;
- final CPDFFormAttribute initAttribute;
- const CPDFFormsConfig(
- {this.availableTypes = CPDFFormType.values,
- this.availableTools = CPDFFormConfigTool.values,
- this.initAttribute = const CPDFFormAttribute()});
- Map<String, dynamic> toJson() => {
- 'availableTypes': availableTypes.map((e) => e.name).toList(),
- 'availableTools': availableTools.map((e) => e.name).toList(),
- 'initAttribute': initAttribute.toJson()
- };
- }
- class CPDFFormAttribute {
- final CPDFFormAttr textField;
- final CPDFFormAttr checkBox;
- final CPDFFormAttr radioButton;
- final CPDFFormAttr listBox;
- final CPDFFormAttr comboBox;
- final CPDFFormAttr pushButton;
- final CPDFFormAttr signaturesFields;
- const CPDFFormAttribute({
- this.textField = const CPDFFormAttr.textField(),
- this.checkBox = const CPDFFormAttr.checkBox(),
- this.radioButton = const CPDFFormAttr.radioButton(),
- this.listBox = const CPDFFormAttr.listBox(),
- this.comboBox = const CPDFFormAttr.comboBox(),
- this.pushButton = const CPDFFormAttr.pushButton(),
- this.signaturesFields = const CPDFFormAttr.signaturesFields(),
- });
- Map<String, dynamic> toJson() => {
- 'textField': textField.toJson(),
- 'checkBox': checkBox.toJson(),
- 'radioButton': radioButton.toJson(),
- 'listBox': listBox.toJson(),
- 'comboBox': comboBox.toJson(),
- 'pushButton': pushButton.toJson(),
- 'signaturesFields': signaturesFields.toJson()
- };
- }
- class CPDFFormAttr {
- final CPDFFormType formType;
- final Color fillColor;
- final Color borderColor;
- final int borderWidth;
- final Color fontColor;
- final int fontSize;
- final bool isBold;
- final bool isItalic;
- final CPDFAlignment alignment;
- final bool multiline;
- final CPDFTypeface typeface;
- final Color checkedColor;
- final bool isChecked;
- final CPDFCheckStyle checkedStyle;
- final String title;
- const CPDFFormAttr(
- {required this.formType,
- this.fillColor = const Color(0xFFDDE9FF),
- this.borderColor = const Color(0xFF1460F3),
- this.borderWidth = 2,
- this.fontColor = Colors.black,
- this.fontSize = 20,
- this.isBold = false,
- this.isItalic = false,
- this.alignment = CPDFAlignment.left,
- this.multiline = true,
- this.typeface = CPDFTypeface.helvetica,
- this.checkedColor = const Color(0xFF43474D),
- this.isChecked = false,
- this.checkedStyle = CPDFCheckStyle.check,
- this.title = 'Button'});
- const CPDFFormAttr.textField(
- {Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color fontColor = Colors.black,
- int fontSize = 20,
- bool isBold = false,
- bool isItalic = false,
- CPDFAlignment alignment = CPDFAlignment.left,
- bool multiline = true,
- CPDFTypeface typeface = CPDFTypeface.helvetica})
- : this(
- formType: CPDFFormType.textField,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- fontColor: fontColor,
- fontSize: fontSize,
- isBold: isBold,
- isItalic: isItalic,
- alignment: alignment,
- multiline: multiline,
- typeface: typeface);
- const CPDFFormAttr.checkBox(
- {Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color checkedColor = const Color(0xFF43474D),
- bool isChecked = false,
- CPDFCheckStyle checkStyle = CPDFCheckStyle.check})
- : this(
- formType: CPDFFormType.checkBox,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- checkedColor: checkedColor,
- isChecked: isChecked,
- checkedStyle: checkStyle);
- const CPDFFormAttr.radioButton(
- {Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color checkedColor = const Color(0xFF43474D),
- bool isChecked = false,
- CPDFCheckStyle checkStyle = CPDFCheckStyle.circle})
- : this(
- formType: CPDFFormType.radioButton,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- checkedColor: checkedColor,
- isChecked: isChecked,
- checkedStyle: checkStyle);
- const CPDFFormAttr.listBox({
- Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color fontColor = Colors.black,
- int fontSize = 20,
- CPDFTypeface typeface = CPDFTypeface.helvetica,
- bool isBold = false,
- bool isItalic = false,
- }) : this(
- formType: CPDFFormType.listBox,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- fontColor: fontColor,
- fontSize: fontSize,
- typeface: typeface,
- isBold: isBold,
- isItalic: isItalic);
- const CPDFFormAttr.comboBox({
- Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color fontColor = Colors.black,
- int fontSize = 20,
- CPDFTypeface typeface = CPDFTypeface.helvetica,
- bool isBold = false,
- bool isItalic = false,
- }) : this(
- formType: CPDFFormType.comboBox,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- fontColor: fontColor,
- fontSize: fontSize,
- typeface: typeface,
- isBold: isBold,
- isItalic: isItalic);
- const CPDFFormAttr.pushButton({
- String title = 'Button',
- Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2,
- Color fontColor = Colors.black,
- int fontSize = 20,
- CPDFTypeface typeface = CPDFTypeface.helvetica,
- bool isBold = false,
- bool isItalic = false,
- }) : this(
- formType: CPDFFormType.pushButton,
- title: title,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth,
- fontColor: fontColor,
- fontSize: fontSize,
- typeface: typeface,
- isBold: isBold,
- isItalic: isItalic);
- const CPDFFormAttr.signaturesFields(
- {Color fillColor = const Color(0xFFDDE9FF),
- Color borderColor = const Color(0xFF1460F3),
- int borderWidth = 2})
- : this(
- formType: CPDFFormType.signaturesFields,
- fillColor: fillColor,
- borderColor: borderColor,
- borderWidth: borderWidth);
- Map<String, dynamic> toJson() {
- switch (formType) {
- case CPDFFormType.textField:
- return {
- 'fillColor': fillColor.toHex(),
- 'borderColor': borderColor.toHex(),
- 'borderWidth': borderWidth,
- 'fontColor': fontColor.toHex(),
- 'fontSize': fontSize,
- 'isBold': isBold,
- 'isItalic': isItalic,
- 'alignment': alignment.name,
- 'multiline': multiline,
- 'typeface': typeface.getFontName()
- };
- case CPDFFormType.checkBox:
- case CPDFFormType.radioButton:
- return {
- 'fillColor': fillColor.toHex(),
- 'borderColor': borderColor.toHex(),
- 'borderWidth': borderWidth,
- 'checkedColor': checkedColor.toHex(),
- 'isChecked': false,
- 'checkedStyle': checkedStyle.name
- };
- case CPDFFormType.listBox:
- case CPDFFormType.comboBox:
- return {
- 'fillColor': fillColor.toHex(),
- 'borderColor': borderColor.toHex(),
- 'borderWidth': borderWidth,
- 'fontColor': fontColor.toHex(),
- 'fontSize': fontSize,
- 'typeface': typeface.getFontName(),
- 'isBold': isBold,
- 'isItalic': isItalic,
- };
- case CPDFFormType.pushButton:
- return {
- 'fillColor': fillColor.toHex(),
- 'borderColor': borderColor.toHex(),
- 'borderWidth': borderWidth,
- 'fontColor': fontColor.toHex(),
- 'fontSize': fontSize,
- 'typeface': typeface.getFontName(),
- 'isBold': isBold,
- 'isItalic': isItalic,
- 'title': title
- };
- case CPDFFormType.signaturesFields:
- return {
- 'fillColor': fillColor.toHex(),
- 'borderColor': borderColor.toHex(),
- 'borderWidth': borderWidth,
- };
- default:
- return {};
- }
- }
- }
- class CPDFGlobalConfig {
- /// Only supports Android platform in version 2.0.2
- // Set the view theme mode except the PDF area, the default value is [CPDFThemeMode.system]
- final CPDFThemeMode themeMode;
- const CPDFGlobalConfig({this.themeMode = CPDFThemeMode.system});
- Map<String, dynamic> toJson() => {"themeMode": themeMode.name};
- }
|