iOS 中 HTML 到 PDF 总是黑屏 - React Native

问题描述 投票:0回答:1

我正在使用

react-native-html-to-pdf
包将 html 内容转换为 pdf,这在 Android 上运行良好,但 iOS 总是返回空白屏幕。

    const options = {
      html: htmlContent,
      fileName:
        voucher.clientID.toString() + ' - ' + voucher.archiveNo.toString(),
      directory: 'Documents',
    };

    const pdfFile: any = await RNHTMLtoPDF.convert(options);

谁有这个问题的解决方案吗?

html ios react-native pdf html-to-pdf
1个回答
0
投票

检查您的 iOS 应用程序是否具有写入提供的目录(“文档”)所需的权限。要在 iOS 上执行文件操作,您可能需要使用 RNFS(React Native File System)包。使您的程序有权写入 Documents 目录。

import RNFS from 'react-native-fs';

const path = RNFS.DocumentDirectoryPath + '/' + options.fileName + '.pdf';
const pdfFile = await RNHTMLtoPDF.convert({ ...options, filePath: path });
© www.soinside.com 2019 - 2024. All rights reserved.