App.tsx 3.2 KB

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