首页 > 解决方案 > React native - 通过让用户在文本字段中输入来编辑 pdf

问题描述

我正在使用 react native 来重建一个类似于 Adob​​e Fill & Sign 的 android 应用程序。问题是,我不知道如何让用户点击 pdf,在用户点击的 pdf 顶部呈现文本字段,并让用户在其中输入。

任何人都知道如何做到这一点?谢谢。

标签: androidreact-nativepdf

解决方案


我的想法是在 pdf 视图上放置一个透明视图,这将触发对话框打开,就像我在警报下方触发一样。您的对话框将包含您想要的 TextInput:(您可以计算用户按下的 x 和 y 坐标,然后在该位置触发对话框以获得您想要的内容)

<View>
    <View> {/* this view will be the pdf*/}
      <Text>{"backgroundView_place of pdf for example"}</Text>
      <Text>{"More pdf texts"}</Text>
    </View>
 {/* this view will be over the pdf and onClick some dialog with input will be triggered, i use alert for example*/}
    <TouchableWithoutFeedback
      onPress={() => {
        alert("InputDialog will be opened here");
      }}
    >
      <View
        style={{
          position: "absolute",
          height: 600,
          width: 300,
          backgroundColor: "transparent"
        }}
      />
    </TouchableWithoutFeedback>
</View>

您可以使用react-native-dialog或任何其他允许您在其中添加 TextInput 或您希望在其中的任何组件的对话框库。
注意:我使用 TouchableWithoutFeedback,这样点击时不会发生任何影响,比如改变不透明度或突出显示等。


推荐阅读