cpdf_document_info_page.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. ///
  2. /// Copyright © 2014-2023 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. import 'package:compdfkit_flutter/common/util/Strings.dart';
  9. import 'package:compdfkit_flutter/common/util/cpdf_date_util.dart';
  10. import 'package:compdfkit_flutter/core/document/cpdf_document.dart';
  11. import 'package:compdfkit_flutter/core/document/cpdf_info.dart';
  12. import 'package:compdfkit_flutter/core/document/cpdf_permissions_info.dart';
  13. import 'package:compdfkit_flutter/widgets/common/views/cpdf_scaffold.dart';
  14. import 'package:compdfkit_flutter/widgets/common/views/cpdf_tool_bar.dart';
  15. import 'package:flutter/material.dart';
  16. class CPDFDocumentInfoPage extends StatefulWidget {
  17. final bool isDark;
  18. final CPDFDocument document;
  19. const CPDFDocumentInfoPage(
  20. {Key? key, this.isDark = false, required this.document})
  21. : super(key: key);
  22. @override
  23. State<CPDFDocumentInfoPage> createState() => _CPDFDocumentInfoPageState();
  24. }
  25. class _CPDFDocumentInfoPageState extends State<CPDFDocumentInfoPage> {
  26. @override
  27. Widget build(BuildContext context) {
  28. return CPDFScaffold(
  29. isDark: widget.isDark,
  30. appBar: CPDFToolbar.normal(
  31. context: context,
  32. titleText: Strings.DocumentInfo,
  33. leadingOnPressed: () {
  34. Navigator.pop(context);
  35. },
  36. ),
  37. body:ListView(children: [_documentInfo(), _permissionInfo()],),
  38. );
  39. }
  40. Widget _documentInfo() {
  41. return FutureBuilder(
  42. future: widget.document.getInfo(),
  43. builder: (context, snapshot) {
  44. if (snapshot.connectionState == ConnectionState.done &&
  45. snapshot.hasData) {
  46. CPDFInfo info = snapshot.data!;
  47. return Column(
  48. children: [
  49. const CPDFDocumentInfoTitle(title: Strings.Abstract),
  50. CPDFDocumentInfoItem(
  51. title: Strings.FileName, content: info.fileName),
  52. CPDFDocumentInfoItem(
  53. title: Strings.FileSize, content: info.fileSizeStr()),
  54. CPDFDocumentInfoItem(title: Strings.Title, content: info.title),
  55. CPDFDocumentInfoItem(
  56. title: Strings.Author, content: info.author),
  57. CPDFDocumentInfoItem(
  58. title: Strings.Subject, content: info.subject),
  59. CPDFDocumentInfoItem(
  60. title: Strings.Keywords, content: info.keywords),
  61. const CPDFDocumentInfoTitle(title: Strings.CreateInformation),
  62. CPDFDocumentInfoItem(
  63. title: Strings.Version,
  64. content: info.majorVersion.toString()),
  65. CPDFDocumentInfoItem(
  66. title: Strings.Pages, content: info.pageCount.toString()),
  67. CPDFDocumentInfoItem(
  68. title: Strings.Creator, content: info.creator),
  69. CPDFDocumentInfoItem(
  70. title: Strings.CreationDate,
  71. content: CPDFDateUtil.format(info.creationDate)),
  72. CPDFDocumentInfoItem(
  73. title: Strings.ModificationDate,
  74. content: CPDFDateUtil.format(info.modificationDate)),
  75. ],
  76. );
  77. } else {
  78. return const Padding(padding: EdgeInsets.zero);
  79. }
  80. });
  81. }
  82. Widget _permissionInfo() {
  83. return FutureBuilder(
  84. future: widget.document.getPermissionsInfo(),
  85. builder: (context, snapshot) {
  86. if (snapshot.connectionState == ConnectionState.done &&
  87. snapshot.hasData) {
  88. CPDFPermissionsInfo info = snapshot.data!;
  89. return Column(
  90. children: [
  91. const CPDFDocumentInfoTitle(title: Strings.CreateInformation),
  92. CPDFDocumentInfoItem(
  93. title: Strings.Printing,
  94. content: _allowStr(info.allowsPrinting)),
  95. CPDFDocumentInfoItem(
  96. title: Strings.ContentCopying, content: _allowStr(info.allowsCopying)),
  97. CPDFDocumentInfoItem(
  98. title: Strings.DocumentChange, content: _allowStr(info.allowsDocumentChanges)),
  99. CPDFDocumentInfoItem(
  100. title: Strings.DocumentAssembly,
  101. content: _allowStr(info.allowsDocumentAssembly)),
  102. CPDFDocumentInfoItem(
  103. title: Strings.Commenting,
  104. content: _allowStr(info.allowsCommenting)),
  105. CPDFDocumentInfoItem(
  106. title: Strings.FillingOfFormField,
  107. content: _allowStr(info.allowsFormFieldEntry)),
  108. ],
  109. );
  110. } else {
  111. return const Padding(padding: EdgeInsets.zero);
  112. }
  113. });
  114. }
  115. String _allowStr(bool allow) {
  116. return allow ? Strings.Allowed : Strings.NotAllowed;
  117. }
  118. }
  119. class CPDFDocumentInfoTitle extends StatelessWidget {
  120. final String title;
  121. const CPDFDocumentInfoTitle({Key? key, required this.title})
  122. : super(key: key);
  123. @override
  124. Widget build(BuildContext context) {
  125. return Container(
  126. alignment: Alignment.centerLeft,
  127. height: 28,
  128. padding: const EdgeInsets.symmetric(horizontal: 16),
  129. color: Theme.of(context).colorScheme.secondaryContainer,
  130. child: Text(
  131. title,
  132. style: Theme.of(context).textTheme.labelMedium,
  133. ),
  134. );
  135. }
  136. }
  137. class CPDFDocumentInfoItem extends StatelessWidget {
  138. final String title;
  139. final String content;
  140. const CPDFDocumentInfoItem(
  141. {Key? key, required this.title, required this.content})
  142. : super(key: key);
  143. @override
  144. Widget build(BuildContext context) {
  145. return Container(
  146. color: Theme.of(context).colorScheme.background,
  147. padding: const EdgeInsets.only(left: 16),
  148. child: Column(
  149. children: [
  150. SizedBox(
  151. height: 56,
  152. child: Row(
  153. mainAxisSize: MainAxisSize.max,
  154. children: [
  155. Text('$title:',
  156. style: Theme.of(context).textTheme.labelLarge),
  157. Expanded(
  158. child: Container(
  159. alignment: Alignment.centerRight,
  160. padding: const EdgeInsets.only(left: 10, right: 16),
  161. child: Text(
  162. content,
  163. style: Theme.of(context).textTheme.bodyMedium?.copyWith(
  164. color:
  165. Theme.of(context).colorScheme.primaryContainer),
  166. ),
  167. ))
  168. ],
  169. )),
  170. const Divider(height: 0.5)
  171. ],
  172. ));
  173. }
  174. }