繁体   English   中英

查看 webview 中的 base64 pdf 在 Z1BDF605991920DB11CBDF8508204 上反应本机?

[英]View base64 pdf in webview react native on iOS?

这是我正在尝试的

const [pdf, setPdf] = useState("")

let image = "data:application/pdf;base64," + curr.Body.toString('base64');

setPdf(image)

<WebView
            style={styles.pdf}
            useWebKit={true}
            originWhitelist={['*']}
            scrollEnabled={true}
            mediaPlaybackRequiresUserAction={true}
            source={{
                html: `
            <html>
            <object data="${pdf}" type="application/pdf">
                <embed 
                    scrollbar="1" 
                    src="${pdf}" 
                    type="application/pdf" 
                   
                />
            </object>
            </html>
            ` }}
        />

以下是我得到的。 PDF 包含 5 页,但屏幕上只有一个。

在此处输入图像描述

帮助我获得完整的 pdf 视图。

尝试使用 ScrollView 包装您的代码以使内容可见/可滚动:

<SafeAreaView style={{flex: 1}}>
      <ScrollView
        style={{ width: '100%' }}
        contentContainerStyle={{ flexGrow: 1 }}
      >
        <WebView
            style={styles.pdf}
            useWebKit={true}
            originWhitelist={['*']}
            scrollEnabled={true}
            mediaPlaybackRequiresUserAction={true}
            source={{
                html: `
            <html>
            <object data="${pdf}" type="application/pdf">
                <embed 
                    scrollbar="1" 
                    src="${pdf}" 
                    type="application/pdf" 
                   
                />
            </object>
            </html>
            ` }}
        />
      </ScrollView>
    </SafeAreaView>

或者你可以使用专门用于阅读pdf的库,例如: https://www.npmjs.com/package/rn-pdf-reader-js下面是一个例子:

<PDFReader
    style={{flex:1, flexGrow:1}}
        source={{
          uri: 'http://www.africau.edu/images/default/sample.pdf',
        }}
      />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM