react-native-pdf文件不是PDF格式或已损坏

k97glaaz  于 6个月前  发布在  React
关注(0)|答案(3)|浏览(108)

我可以打开链接:https://www.orimi.com/pdf-test.pdf,但是当我尝试使用链接:http://94.23.154.57:8081/digital-cert/download-file?id=33FB3234-23EC-472B-AB6F-76436DDCFA45&view=1时,我无法打开它。我收到错误消息:Error: cannot create document: File not in PDF format or corrupted.我怀疑http可能导致问题,但PDF链接从服务器返回,我无法将其更改为https

import Pdf from 'react-native-pdf';
import {
  View,
} from 'react-native';

const PDFExample = ({route}) => {
  const source = {
    uri: 'http://94.23.154.57:8081/digital-cert/download-file?id=33FB3234-23EC-472B-AB6F-76436DDCFA45&view=1',
    cache: true,
  };
  return (
      <View style={styles.container}>
        <Pdf
          trustAllCerts={false}
          source={source}
          onLoadComplete={(numberOfPages, filePath) => {
            console.log(`Number of pages: ${numberOfPages}`);
          }}
          onPageChanged={(page, numberOfPages) => {
            console.log(`Current page: ${page}`);
          }}
          onError={error => {
            console.log(error);
          }}
          onPressLink={uri => {
            console.log(`Link pressed: ${uri}`);
          }}
          style={styles.pdf}
        />
      </View>
)
}

字符串

4jb9z9bj

4jb9z9bj1#

该文件是严重损坏这里是真正的文件夹(文件结束)在大约10%的下载。真正的文件大小应该是125062,其余的总1,106,569字节应被删除。一旦你删除HTML脚本,它应该在任何PDF查看器完美工作。
下载损坏的文件通过

curl -o download.pdf http://94.23.154.57:8081/digital-cert/download-file?id=33FB3234-23EC-472B-AB6F-76436DDCFA45

字符串
最简单的更正是“打开”的Xplayer Reader,并简单地让它重建关闭的文件,没有拖车充满行李。固定文件大小则为124,125字节。


的数据

3yhwsihp

3yhwsihp2#

PDF插件不会打开损坏的格式PDF,即使我尝试下载并打开file://,但它不为我工作。
这也可能表明支持PDF文件丢失或部分下载,有很多原因导致PDF文件损坏。我发现6原因
1.下载过程中出错
1.使用不兼容的软件
1.一些电子邮件服务提供商的编码
1.硬盘问题
1.病毒攻击
1.用不同的软件打开同一个文件
如果你想修复PDF然后检查此文档由Adobe修复损坏的PDF。
如果你不想做所有这些事情,那么你也可以用另一种方式打开PDF。
我们有三个选项可以在React Native中打开PDF,第一个你已经完成了,现在你可以选择其他两个

  • react-native-webview
  • react-native-file-viewer

如果你选择webview然后检查这个answer由aytek回答
您可以使用file viewer打开PDF

示例:

const path = FileViewer.open(path, { showOpenWithDialog: true }) // absolute-path-to-my-local-file.
  .then(() => {
    // success
  })
  .catch((error) => {
    // error
  });

字符串

yc0p9oo0

yc0p9oo03#

如果你怀疑它是http vs https,你可以尝试这个解决方案来修复iOS。
将以下内容添加到您的info.plist中,如本答案所述:
https://stackoverflow.com/a/38427829/11729637

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

字符串

相关问题