App.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. */
  9. import React, { Component } from 'react';
  10. import configuration from './assets/configuration.json';
  11. import DocumentPicker from 'react-native-document-picker'
  12. import {
  13. StyleSheet,
  14. Text,
  15. View,
  16. TouchableOpacity
  17. } from 'react-native';
  18. import { ComPDFKit } from 'react-native-compdfkit-pdf';
  19. import { CPDFConfiguration, CPDFModeConfig } from '../src/configuration/CPDFConfiguration';
  20. type Props = {
  21. };
  22. export default class App extends Component<Props> {
  23. state = {
  24. versionCode: ''
  25. }
  26. constructor(props: Props) {
  27. super(props)
  28. ComPDFKit.initialize('vxwRHJC9RDKK0He2jTpepBkrolOnPQt7bxjfIiqqcJc=', 'vTXxqCm2rutpV67wRy+UnBSJzDBwG0/DLjiLL61zxxc=')
  29. this.getVersionCode()
  30. }
  31. async getVersionCode() {
  32. var version = await ComPDFKit.getVersionCode()
  33. console.log(version)
  34. this.setState({
  35. versionCode: version
  36. })
  37. }
  38. render() {
  39. return (
  40. <View style={styles.scaffold}>
  41. <View style={styles.appBar}>
  42. <Text style={styles.mediumTitle}>
  43. ComPDFKit PDF SDK for ReactNative
  44. </Text>
  45. </View>
  46. <View style={styles.container}>
  47. <TouchableOpacity onPress={() => {
  48. // var ve : string = 'file:///android_asset/pdf_document.pdf'
  49. // ComPDFKit.openDocument(ve, '', JSON.stringify(configuration))
  50. const configuration : CPDFConfiguration = {
  51. modeConfig: {
  52. initialViewMode: CPDFModeConfig.ViewMode.VIEWER,
  53. availableViewModes: [
  54. CPDFModeConfig.ViewMode.VIEWER,
  55. CPDFModeConfig.ViewMode.ANNOTATIONS,
  56. CPDFModeConfig.ViewMode.CONTENT_EDITOR,
  57. CPDFModeConfig.ViewMode.FORMS,
  58. CPDFModeConfig.ViewMode.SIGNATURES
  59. ]
  60. }
  61. }
  62. var json = JSON.stringify(configuration)
  63. ComPDFKit.testConfig(json)
  64. }}>
  65. <View style={styles.funItem}>
  66. <Text style={{ fontWeight: 'bold' }}>{'Open Sample'}</Text>
  67. </View>
  68. </TouchableOpacity>
  69. <View style={styles.dividingLine} />
  70. <TouchableOpacity onPress={() => {
  71. try {
  72. const pickerResult = DocumentPicker.pick({
  73. type: [DocumentPicker.types.pdf]
  74. });
  75. pickerResult.then(res => {
  76. ComPDFKit.openDocument(res[0]?.uri as string, '', JSON.stringify(configuration))
  77. })
  78. } catch (err) {
  79. }
  80. }}>
  81. <View style={styles.funItem}>
  82. <Text style={{ fontWeight: 'bold' }}>{'Pick Document'}</Text>
  83. </View>
  84. <View style={styles.dividingLine} />
  85. </TouchableOpacity>
  86. <View style={styles.buttom}>
  87. <Text style={styles.body2}>ComPDFKit {this.state.versionCode}</Text>
  88. </View>
  89. </View>
  90. </View>
  91. );
  92. }
  93. }
  94. const styles = StyleSheet.create({
  95. appBar: {
  96. height: 56,
  97. backgroundColor: '#FAFCFF',
  98. elevation: 4,
  99. flexDirection: "row",
  100. justifyContent: "space-between",
  101. alignItems: "center",
  102. padding: 16
  103. },
  104. mediumTitle: {
  105. fontSize: 16,
  106. },
  107. body2: {
  108. textAlign: 'center',
  109. fontSize: 12
  110. },
  111. scaffold: {
  112. flex: 1,
  113. },
  114. container: {
  115. marginHorizontal: 16,
  116. marginVertical: 8,
  117. flex: 1,
  118. // backgroundColor: '#F5FCFF',
  119. },
  120. funItem: {
  121. height: 56,
  122. justifyContent: 'center',
  123. textAlign: 'center'
  124. },
  125. dividingLine: {
  126. height: 0.5, backgroundColor: '#4D333333', width: '100%'
  127. },
  128. buttom: {
  129. flex: 1,
  130. justifyContent: 'flex-end',
  131. }
  132. });