CPDFConfiguration.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /**
  2. * Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  3. *
  4. * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  5. * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  6. * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  7. * This notice may not be removed from this file.
  8. */
  9. import { BorderWidth, ColorAlpha, CPDFAlignment, CPDFAnnotationType, CPDFBorderStyle, CPDFCheckStyle, CPDFConfigTool, CPDFContentEditorType, CPDFDisplayMode, CPDFFormType, CPDFLineType, CPDFThemes, CPDFToolbarAction, CPDFToolbarMenuAction, CPDFTypeface, CPDFViewMode, DashGap, FontSize, HexColor, CPDFThemeMode } from "./CPDFOptions";
  10. /**
  11. * Configuration information for displaying PDF using the ComPDFKit.openDocument method.
  12. * Used to configure UI elements, PDF properties, etc.
  13. *
  14. * @example
  15. * const configuration : CPDFConfiguration = {
  16. * modeConfig: {
  17. * initialViewMode: CPDFModeConfig.ViewMode.VIEWER,
  18. * availableViewModes: [
  19. * CPDFModeConfig.ViewMode.VIEWER,
  20. * CPDFModeConfig.ViewMode.ANNOTATIONS,
  21. * CPDFModeConfig.ViewMode.CONTENT_EDITOR,
  22. * CPDFModeConfig.ViewMode.FORMS,
  23. * CPDFModeConfig.ViewMode.SIGNATURES
  24. * ]
  25. * }
  26. * }
  27. *
  28. * ComPDFKit.openDocument(document, 'password', JSON.stringify(configuration))
  29. */
  30. export class CPDFConfiguration {
  31. /**
  32. * PDF mode configuration
  33. */
  34. modeConfig?: {
  35. /**
  36. * Default mode to display when opening the PDF View, default is [CPDFToolbarAction.VIEWER]
  37. */
  38. initialViewMode?: CPDFViewMode,
  39. readerOnly?: boolean,
  40. /**
  41. * Configure supported modes
  42. */
  43. availableViewModes?: CPDFViewMode[]
  44. }
  45. /**
  46. * Configuration for top toolbar functionality
  47. */
  48. toolbarConfig?: {
  49. /**
  50. * Top toolbar actions for Android platform
  51. *
  52. * Default: thumbnail, search, bota, menu.
  53. *
  54. * {@link CPDFToolbarAction.BACK} button will be shown only on the far left
  55. */
  56. androidAvailableActions?: CPDFToolbarAction[],
  57. /**
  58. * Left toolbar actions for iOS platform
  59. *
  60. * Default: back, thumbnail
  61. */
  62. iosLeftBarAvailableActions?: CPDFToolbarAction[],
  63. /**
  64. * Right toolbar actions for iOS platform
  65. *
  66. * Default: search, bota, menu
  67. */
  68. iosRightBarAvailableActions?: CPDFToolbarAction[],
  69. /**
  70. * Configure the menu options opened in the top toolbar {@link CPDFToolbarAction.MENU}
  71. */
  72. availableMenus?: CPDFToolbarMenuAction[]
  73. }
  74. /**
  75. * annotation config
  76. */
  77. annotationsConfig?: {
  78. annotationAuthor?: string,
  79. /**
  80. * {@link CPDFViewMode.ANNOTATIONS} mode, list of annotation functions shown at the bottom of the view.
  81. */
  82. availableTypes?: CPDFAnnotationType[],
  83. /**
  84. * {@link CPDFViewMode.ANNOTATIONS} mode, annotation tools shown at the bottom of the view.
  85. */
  86. availableTools?: CPDFConfigTool[],
  87. /**
  88. * When adding an annotation, the annotation’s default attributes.
  89. */
  90. initAttribute?: {
  91. /**
  92. * Note annotation attribute configuration.
  93. * @param { HexColor } [color] HEX color: #1460F3
  94. * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255
  95. */
  96. note?: {
  97. color?: HexColor,
  98. alpha?: ColorAlpha
  99. },
  100. /**
  101. * Highlight annotation attribute configuration.
  102. * @param { HexColor } [color] HEX color: #1460F3.
  103. * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255.
  104. */
  105. highlight?: {
  106. color?: HexColor,
  107. alpha?: ColorAlpha
  108. },
  109. /**
  110. * Underline annotation attribute configuration.
  111. * @param { HexColor } [color] HEX color: #1460F3
  112. * @param { number } [alpha] Color opacity, value range: 0~255
  113. */
  114. underline?: {
  115. color?: HexColor,
  116. alpha?: ColorAlpha
  117. },
  118. /**
  119. * Squiggly annotation attribute configuration.
  120. * @param { HexColor } [color] HEX color: #1460F3
  121. * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255
  122. */
  123. squiggly?: {
  124. color?: HexColor,
  125. alpha?: ColorAlpha
  126. },
  127. /**
  128. * Strikeout annotation attribute configuration.
  129. * @param { HexColor } [color] HEX color: #1460F3
  130. * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255
  131. */
  132. strikeout?: {
  133. color?: HexColor,
  134. alpha?: ColorAlpha
  135. },
  136. /**
  137. * Ink annotation attribute configuration.
  138. * @param { HexColor } [color] HEX color: #1460F3
  139. * @param { ColorAlpha } [alpha] Color opacity, value range: 0~255
  140. * @param { BorderWidth } [borderWidth] Brush thickness, value range: 1~10
  141. */
  142. ink?: {
  143. color?: HexColor,
  144. alpha?: ColorAlpha,
  145. borderWidth?: BorderWidth
  146. },
  147. /**
  148. * square annotation attribute configuration.
  149. * @param { HexColor } [fillColor] HEX color: #1460F3
  150. * @param { HexColor } [borderColor] HEX color: #1460F3
  151. * @param { ColorAlpha } [colorAlpha] fill color and border color opacity. value range:0~255
  152. * @param { BorderWidth } [borderWidth] border thickness, value range:1~10
  153. * @param { object } [borderStyle] Set the border style to dashed or solid.
  154. */
  155. square?: {
  156. fillColor?: HexColor,
  157. borderColor?: HexColor,
  158. colorAlpha?: ColorAlpha,
  159. borderWidth?: BorderWidth,
  160. borderStyle?: {
  161. /**
  162. * default: {@link CPDFBorderStyle.SOLID}
  163. */
  164. style?: CPDFBorderStyle,
  165. /**
  166. * Dashed gap, only style={@link CPDFBorderStyle.DASHED} is valid.
  167. */
  168. dashGap?: DashGap
  169. }
  170. },
  171. /**
  172. * Circle annotation attribute configuration.
  173. * @param { HexColor } [fillColor] HEX color: #1460F3
  174. * @param { HexColor } [borderColor] HEX color: #1460F3
  175. * @param { ColorAlpha } [colorAlpha] fill color and border color opacity. value range:0~255
  176. * @param { BorderWidth } [borderWidth] border thickness, value range:1~10
  177. * @param { object } [borderStyle] Set the border style to dashed or solid.
  178. */
  179. circle?: {
  180. fillColor?: HexColor,
  181. borderColor?: HexColor,
  182. colorAlpha?: ColorAlpha,
  183. borderWidth?: BorderWidth,
  184. borderStyle?: {
  185. /**
  186. * default: {@link CPDFBorderStyle.SOLID}
  187. */
  188. style?: CPDFBorderStyle,
  189. /**
  190. * Dashed gap, only style={@link CPDFBorderStyle.DASHED} is valid.
  191. */
  192. dashGap?: DashGap
  193. }
  194. },
  195. /**
  196. * Line annotation attribute configuration.
  197. * @param { HexColor } [borderColor] HEX color: #1460F3
  198. * @param { ColorAlpha } [borderAlpha] line color opacity. value range:0~255
  199. * @param { BorderWidth } [borderWidth] border thickness, value range:1~10
  200. * @param { object } [borderStyle] Set the border style to dashed or solid.
  201. */
  202. line?: {
  203. borderColor?: HexColor,
  204. borderAlpha?: ColorAlpha,
  205. borderWidth?: BorderWidth,
  206. borderStyle?: {
  207. /**
  208. * default: {@link CPDFBorderStyle.SOLID}
  209. */
  210. style?: CPDFBorderStyle,
  211. /**
  212. * Dashed gap, only style={@link CPDFBorderStyle.DASHED} is valid.
  213. */
  214. dashGap?: DashGap
  215. }
  216. },
  217. /**
  218. * Arrow annotation attribute configuration.
  219. * @param { HexColor } [borderColor] HEX color: #1460F3
  220. * @param { ColorAlpha } [borderAlpha] line color opacity. value range:0~255
  221. * @param { BorderWidth } [borderWidth] border thickness, value range:0~10
  222. * @param { object } [borderStyle] Set the border style to dashed or solid.
  223. * @param { CPDFLineType } [startLineType] Arrow starting position shape.
  224. * @param { CPDFLineType } [tailLineType] Arrow tail position shape.
  225. */
  226. arrow?: {
  227. borderColor?: HexColor,
  228. borderAlpha?: ColorAlpha,
  229. borderWidth?: BorderWidth,
  230. borderStyle?: {
  231. /**
  232. * default: {@link CPDFBorderStyle.SOLID}
  233. */
  234. style?: CPDFBorderStyle,
  235. /**
  236. * Dashed gap, only style={@link CPDFBorderStyle.DASHED} is valid.
  237. */
  238. dashGap?: DashGap
  239. },
  240. startLineType?: CPDFLineType
  241. tailLineType?: CPDFLineType
  242. },
  243. /**
  244. * Freetext annotation attribute configuration.
  245. * @param { HexColor } [fontColor] HEX color: #1460F3
  246. * @param { ColorAlpha } [fontColorAlpha] text color opacity. value range:0~255
  247. * @param { FontSize } [fontSize] font size, value range:1~100
  248. * @param { boolean } [isBold] Whether the font is bold.
  249. * @param { boolean } [isItalic] Is the font italicized.
  250. * @param { CPDFAlignment } [alignment] Text alignment, {@link CPDFAlignment.LEFT} aligned by default.
  251. * @param { CPDFTypeface } [typeface] The font used by default for text. The default is:{@link CPDFTypeface.HELVETICA}.
  252. */
  253. freeText?: {
  254. fontColor?: HexColor,
  255. fontColorAlpha?: ColorAlpha,
  256. fontSize?: FontSize,
  257. isBold?: boolean,
  258. isItalic?: boolean,
  259. alignment?: CPDFAlignment,
  260. typeface?: CPDFTypeface
  261. }
  262. }
  263. }
  264. contentEditorConfig?: {
  265. /**
  266. * Content editing mode, the editing mode displayed at the bottom of the view
  267. * Default order: editorText, editorImage
  268. */
  269. availableTypes?: CPDFContentEditorType[],
  270. /**
  271. * Available tools, including: Setting, Undo, Redo
  272. */
  273. availableTools?: CPDFConfigTool[]
  274. initAttribute?: {
  275. /**
  276. * When adding text, the text default properties
  277. * @param { HexColor } [fontColor] HEX color: #1460F3
  278. * @param { ColorAlpha } [fontColorAlpha] text color opacity. value range:0~255
  279. * @param { FontSize } [fontSize] font size, value range:1~100
  280. * @param { boolean } [isBold] Whether the font is bold.
  281. * @param { boolean } [isItalic] Is the font italicized.
  282. * @param { CPDFAlignment } [alignment] Text alignment, {@link CPDFAlignment.LEFT} aligned by default.
  283. * @param { CPDFTypeface } [typeface] The font used by default for text. The default is:{@link CPDFTypeface.HELVETICA}.
  284. */
  285. text?: {
  286. fontColor?: HexColor,
  287. fontColorAlpha?: ColorAlpha,
  288. fontSize?: FontSize,
  289. isBold?: boolean,
  290. isItalic?: boolean,
  291. alignment?: CPDFAlignment,
  292. typeface?: CPDFTypeface
  293. }
  294. }
  295. }
  296. formsConfig?: {
  297. /**
  298. * In {@link CPDFViewMode.Forms} mode, the list of form types at the bottom of the view.
  299. */
  300. availableTypes?: CPDFFormType[]
  301. /**
  302. * Only supports {@link CPDFConfigTool.UNDO} and {@link CPDFConfigTool.UNDO} .
  303. */
  304. availableTools?: CPDFConfigTool[]
  305. /**
  306. * Form default attribute configuration
  307. */
  308. initAttribute?: {
  309. /**
  310. * Text field default properties, such as fill color, border color, text style, etc.
  311. */
  312. textField?: {
  313. fillColor?: HexColor,
  314. borderColor?: HexColor,
  315. borderWidth?: BorderWidth,
  316. fontColor?: HexColor,
  317. fontSize?: FontSize,
  318. isBold?: boolean,
  319. isItalic?: boolean,
  320. alignment?: CPDFAlignment,
  321. multiline?: boolean,
  322. typeface?: CPDFTypeface
  323. },
  324. checkBox?: CheckBoxAttr,
  325. radioButton?: RadioButtonAttr,
  326. listBox?: ListBoxAttr,
  327. comboBox?: ComboBoxAttr,
  328. pushButton?: {
  329. fillColor?: HexColor,
  330. borderColor?: HexColor,
  331. borderWidth?: BorderWidth,
  332. fontColor?: HexColor,
  333. fontSize?: FontSize,
  334. title?: string,
  335. typeface?: CPDFTypeface,
  336. isBold?: boolean,
  337. isItalic?: boolean,
  338. },
  339. signaturesFields?: {
  340. fillColor?: HexColor,
  341. borderColor?: HexColor,
  342. borderWidth?: number
  343. }
  344. }
  345. }
  346. /**
  347. * PDF View configuration.
  348. */
  349. readerViewConfig?: {
  350. /**
  351. * Sets whether hyperlinks in the PDF document annotations are highlighted.
  352. */
  353. linkHighlight?: boolean,
  354. /**
  355. * Sets whether form fields in the PDF document are highlighted.
  356. */
  357. formFieldHighlight?: boolean,
  358. /**
  359. * Display mode of the PDF document, single page, double page, or book mode.
  360. * Default: {@link CPDFDisplayMode.SINGLE_PAGE}
  361. */
  362. displayMode?: CPDFDisplayMode,
  363. /**
  364. * Whether PDF page flipping is continuous scrolling.
  365. */
  366. continueMode?: boolean,
  367. /**
  368. * Whether scrolling is in vertical direction.
  369. * `true`: Vertical scrolling, `false`: Horizontal scrolling.
  370. * Default: true
  371. */
  372. verticalMode?: boolean,
  373. /**
  374. * Cropping mode.
  375. * Whether to crop blank areas of PDF pages.
  376. * Default: false
  377. */
  378. cropMode?: boolean,
  379. /**
  380. * Theme color.
  381. * Default: {@link CPDFThemes.light}
  382. */
  383. themes?: CPDFThemes,
  384. /**
  385. * Whether to display the sidebar quick scroll bar.
  386. */
  387. enableSliderBar?: boolean,
  388. /**
  389. * Whether to display the bottom page indicator.
  390. */
  391. enablePageIndicator?: boolean,
  392. /**
  393. * Spacing between each page of the PDF, default 10px.
  394. */
  395. pageSpacing?: number,
  396. /**
  397. * Page scale value, default 1.0.
  398. */
  399. pageScale?: number,
  400. /**
  401. * only android platform.
  402. */
  403. pageSameWidth?: boolean
  404. }
  405. global? : {
  406. themeMode?: CPDFThemeMode,
  407. fileSaveExtraFontSubset?: boolean
  408. }
  409. };
  410. /**
  411. * @param { HexColor } [fillColor] HEX color: #1460F3
  412. * @param { HexColor } [borderColor] HEX color: #1460F3
  413. * @param { BorderWidth } [borderWidth] border thickness, value range:0~10
  414. * @param { HexColor } [checkedColor]
  415. * @param { boolean } [isChecked]
  416. * @param { CPDFCheckStyle } [checkedStyle]
  417. */
  418. export class CheckBoxAttr {
  419. fillColor?: HexColor
  420. borderColor?: HexColor
  421. borderWidth?: BorderWidth
  422. checkedColor?: HexColor
  423. isChecked?: boolean
  424. checkedStyle?: CPDFCheckStyle
  425. }
  426. export class RadioButtonAttr extends CheckBoxAttr{}
  427. export class ListBoxAttr {
  428. fillColor?: string
  429. borderColor?: string
  430. borderWidth?: number
  431. fontColor?: string
  432. fontSize?: number
  433. typeface?: CPDFTypeface
  434. isBold?: boolean
  435. isItalic?: boolean
  436. }
  437. export class ComboBoxAttr extends ListBoxAttr{}