App.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 React, { Component } from 'react';
  10. import DocumentPicker from 'react-native-document-picker'
  11. import {
  12. StyleSheet,
  13. Text,
  14. View,
  15. TouchableOpacity,
  16. SafeAreaView
  17. } from 'react-native';
  18. import { Platform } from 'react-native';
  19. import { ComPDFKit } from '@compdfkit_pdf_sdk/react_native';
  20. type Props = {};
  21. export default class App extends Component<Props> {
  22. state = {
  23. versionCode: ''
  24. }
  25. constructor(props: Props) {
  26. super(props)
  27. this.initialize()
  28. this.getVersionCode()
  29. }
  30. async getVersionCode() {
  31. // Get the version code of ComPDFKit SDK
  32. var version = await ComPDFKit.getVersionCode()
  33. this.setState({
  34. versionCode: version
  35. })
  36. }
  37. async initialize() {
  38. // Online certification, Fill in your online license
  39. // Returns true if initialization is successful, otherwise returns false.
  40. // var result = await ComPDFKit.initialize('NjYzODcyYTMxOWQzMA==', 'NjYzODcyYTgxM2YwNg==')
  41. // console.log("ComPDFKitRN", "initialize:", result)
  42. // Offline authentication, Fill in your offline license
  43. var result;
  44. if (Platform.OS == 'android') {
  45. result = await ComPDFKit.init_('nGkHDIO2BGVr/RqhP6yQPqO0XXVHekXzzTOR0OwKQRPP0PTIwpOcxIFNXoIi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ZdeMlAGlrXHwS+Ze7Zzsh970FMk51BTvlxKB5gh0zRJb7VwECD2Nw2u0lH1oY17eVN2TRW5amzqSj1QR5Q0MX/v2nFNCjvJImeroTsMiyvSO5KjU5Zrs50W363LuCsh9JihVahrRo+mDgAJSMI2qe6FgOWrSV9NdN1tUqy/YCPxz4PvAib1q0YsbM47koQNz+gWOcywgP1s0vBE/3RNraw+iWcFOaCVAycWSKPP3lIr6+zPIVeNM7/9V+hQcUgoFS+esQrrYEncuhU6kau30e4oZAeZuZW4uCPPnzCZEk9/R0sj1ymWzB5SzrGNfsaQi2wIbQLmf2MR0uIQPwcXfzClC/ew/ZZIftEaBTyRSW/L5h3X09SnC1Ll1zv4sOQxMtrlExwu34ZLOd+DRO7H3qx1BYUfGzzxDFQRFwQ0iZ7xWsXxWc0crZQxjNktT8q4J3K3dzlz2pMXaYCC/i1GyVGRKsr3yekqEvPTzvclvrpTrxPBvbA3x+eEaoo6yq7MhvZzDW1elg2+M68QoaLuDTuBaeMrpFmlS')
  48. }
  49. console.log("ComPDFKitRN", "init_:", result)
  50. }
  51. /**
  52. * Open the sample document embedded in Android or iOS project.
  53. */
  54. openSample() {
  55. var samplePDF: string = Platform.OS == 'android' ? 'file:///android_asset/PDF_Document.pdf' : 'PDF_Document.pdf'
  56. // We provide default UI and PDF property related configurations here, you can modify configuration options according to your needs.
  57. var config = ComPDFKit.getDefaultConfig({})
  58. ComPDFKit.openDocument(samplePDF, '', config)
  59. }
  60. /**
  61. * Pick a PDF file from the local storage of Android or iOS device, this example uses the `react-native-document-picker` package,
  62. * If you want to use this example, please add this package to your project first.
  63. * {@link https://www.npmjs.com/package/react-native-document-picker}
  64. *
  65. */
  66. pickPDFFile() {
  67. try {
  68. const pickerResult = DocumentPicker.pick({
  69. type: [DocumentPicker.types.pdf]
  70. });
  71. pickerResult.then(res => {
  72. ComPDFKit.openDocument(res[0]?.uri as string, '', ComPDFKit.getDefaultConfig({}))
  73. })
  74. } catch (err) {
  75. }
  76. }
  77. render() {
  78. return (
  79. <SafeAreaView style={{ flex: 1 }}>
  80. <View style={styles.scaffold}>
  81. <View style={styles.appBar}>
  82. <Text style={styles.mediumTitle}>
  83. ComPDFKit PDF SDK for ReactNative
  84. </Text>
  85. </View>
  86. <View style={styles.container}>
  87. <TouchableOpacity onPress={() => {
  88. this.openSample()
  89. }}>
  90. <View style={styles.funItem}>
  91. <Text style={{ fontWeight: 'bold' }}>{'Open Sample'}</Text>
  92. </View>
  93. </TouchableOpacity>
  94. <View style={styles.dividingLine} />
  95. <TouchableOpacity onPress={() => {
  96. this.pickPDFFile()
  97. }}>
  98. <View style={styles.funItem}>
  99. <Text style={{ fontWeight: 'bold' }}>{'Pick Document'}</Text>
  100. </View>
  101. <View style={styles.dividingLine} />
  102. </TouchableOpacity>
  103. <View style={styles.buttom}>
  104. <Text style={styles.body2}>ComPDFKit for {Platform.OS == 'android' ? 'Android' : 'iOS'} {this.state.versionCode}</Text>
  105. </View>
  106. </View>
  107. </View>
  108. </SafeAreaView>
  109. );
  110. }
  111. }
  112. const styles = StyleSheet.create({
  113. appBar: {
  114. height: 56,
  115. backgroundColor: '#FAFCFF',
  116. elevation: 4,
  117. flexDirection: "row",
  118. justifyContent: "space-between",
  119. alignItems: "center",
  120. padding: 16
  121. },
  122. mediumTitle: {
  123. fontSize: 16,
  124. },
  125. body2: {
  126. textAlign: 'center',
  127. fontSize: 12
  128. },
  129. scaffold: {
  130. flex: 1,
  131. },
  132. container: {
  133. marginHorizontal: 16,
  134. marginVertical: 8,
  135. flex: 1,
  136. // backgroundColor: '#F5FCFF',
  137. },
  138. funItem: {
  139. height: 56,
  140. justifyContent: 'center',
  141. textAlign: 'center'
  142. },
  143. dividingLine: {
  144. height: 0.5, backgroundColor: '#4D333333', width: '100%'
  145. },
  146. buttom: {
  147. flex: 1,
  148. justifyContent: 'flex-end',
  149. }
  150. });