App.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. Platform,
  14. StyleSheet,
  15. Text,
  16. View,
  17. Button,
  18. NativeModules
  19. } from 'react-native';
  20. const instructions = Platform.select({
  21. ios: 'Press Cmd+R to reload,\n' +
  22. 'Cmd+D or shake for dev menu',
  23. android: 'Double tap R on your keyboard to reload,\n' +
  24. 'Shake or press menu button for dev menu',
  25. });
  26. type Props = {};
  27. export default class App extends Component<Props> {
  28. componentDidMount(){
  29. // offline auth
  30. NativeModules.OpenPDFModule.init_('77/0LbrlNGNUEKWCmu4/iG3ZlSv4+47zdgsGOxDX3vGx64O2BtvxJyDzgqNvAmqU8eM0G0ALjeYHtV3vrL7mNtev5BHDGmg2ye3WigSqpN8y0gOPPutXKAQyW9vM+cC81ws4sjcXt2vphQXKjRGeVnQodoe+0FbKzffywJ2DORo32GO9qJ51qIKGmXhokKOuQIDJ2eDgQDkIwUChC+yVz088AjTSDSYOe0UobLHOpkP6Ou4qbkx6pKJ+WexOqFxIb90cAQVVa02NpLJdSu8VPIDJNzuwds1y2RLVD6lgBj8Zez+CGDL4JzeYnYhQhlOZNLXJQ4ZqkN/eHcvgIlpzL2u0lH1oY17eVN2TRW5amzqOuoo5orgnAvMGFLdEwMLlC+K5dn2h1bB4RjP9ZTqgoNaGtyKiQ+FhqHLgPV+faNMUdCBlrq4FNafN5ZoZwbHn4fzUh88DO0481O/H5F0zHak/PQJR7Gu1OfN94Q2uALpL4t3i0S76cdEeJ6wRw44AH0PQikF7jWqqmAB1bqcqsgePNE97RigZwYiDA0p2AGWxhBg2+pgZD9EPOOjdtWPXK9LTAop75OQ9whjDWL1y0LTP/JhOPQIOghNPepj3VtjzSVrUbTBFktXeDGlz0NH9TnbvjZoxJRlcNN1+9x100WEfF4A2XbJZEjcpxV9tk1r9UpDZNXkuRC5cqSCOndk3WcAQjbXfQ4Bb9zwxbcvORsTU9lFmAbRS4KFSnCfN/gMqYb0QzhAKt6Wube1sAVkj4n7AvEss/0SdC9zk5m0/E/c0dDshJ3XKSLU/PaI1wbf/SnQhn+gZICJWg9lWCAi16kSStNvD+Tlg8iXYGXcUT967Gjfe/7Au1tVEU3oE60OBrEnSCSSJJt3MWbr/52CRpTtQ6bC+eZK0ijaRGZnS60G4A4sqfUpH3dRQ0juEnz0zrfyaQi4TKGCC1SzT5YPtsIEy4Stbdh3CCWoYV8SehrEkB58JHrolHhy5cVPV2RRYE30JXG5sJOlwb6wuhHVLlanJ7OE5ewEJCtZIHMkJ/rlfinOunS0G9GL2IMBwsyfOB1Cxl+yXx4V3li2ymawe')
  31. }
  32. render() {
  33. return (
  34. <View style={styles.container}>
  35. <Text style={styles.welcome}>
  36. Welcome to React Native!
  37. </Text>
  38. <Text style={styles.instructions}>
  39. To get started, edit App.tsx
  40. </Text>
  41. <Text style={styles.instructions}>
  42. {instructions}
  43. </Text>
  44. <Button
  45. title={'Open sample document'}
  46. onPress={() => {
  47. this.jumpToNativeView();
  48. }}
  49. />
  50. <View style={{margin:5}}/>
  51. <Button
  52. title={'pick document'}
  53. onPress={() => {
  54. try {
  55. const pickerResult = DocumentPicker.pick({
  56. type: [DocumentPicker.types.pdf]
  57. });
  58. pickerResult.then(res => {
  59. if (Platform.OS == 'android') {
  60. // only android
  61. NativeModules.OpenPDFModule.openPDFByUri(res[0].uri, '', JSON.stringify(configuration))
  62. } else {
  63. NativeModules.OpenPDFModule.openPDFByConfiguration(res[0].uri, '', JSON.stringify(configuration))
  64. }
  65. })
  66. } catch (err) {
  67. }
  68. }}
  69. />
  70. </View>
  71. );
  72. }
  73. jumpToNativeView() {
  74. NativeModules.OpenPDFModule.openPDF(JSON.stringify(configuration))
  75. // NativeModules.OpenPDFModule.openPDFByConfiguration(filePath, password, JSON.stringify(configuration))
  76. // only android platform
  77. // NativeModules.OpenPDFModule.openPDFByUri(uriString, password, JSON.stringify(configuration))
  78. }
  79. }
  80. const styles = StyleSheet.create({
  81. container: {
  82. flex: 1,
  83. justifyContent: 'center',
  84. alignItems: 'center',
  85. backgroundColor: '#F5FCFF',
  86. },
  87. welcome: {
  88. fontSize: 20,
  89. textAlign: 'center',
  90. margin: 10,
  91. },
  92. instructions: {
  93. textAlign: 'center',
  94. color: '#333333',
  95. marginBottom: 5,
  96. }
  97. });