首页 > 解决方案 > 反应:从调用状态的“blob”打开 PDF。使用“jsPDF”。返回:加载PDF文档失败

问题描述

我试图onClick在调用axios.get(). 从mysql数据库中获取数据。

打开pdf的按钮代码是

class DownloadPdf extends Component {
    constructor(props) {
        super(props)
        this.pdfGenerator = this.pdfGenerator.bind(this)
    }
    pdfGenerator(blob){
        console.log(blob)
        var doc = new jsPDF('p', 'pt');
        var blobPDF = new Blob([doc.output[blob.data]], { type: 'application/pdf'})
        var BlobURL = URL.createObjectURL(blobPDF)
        window.open(BlobURL)

    }
render() {
    return (
        <td>
        <button onClick={()=>{this.pdfGenerator(this.props.blob)}}>
            Download PDF
        </button>
        </td>
    )
}

输入道具是properties[obj].pdf_blob

blob 对象是: {type: "Buffer", data: Array(94869)}

在父母中我使用过

.then(res => { this.setState({
    properties: res.data.data,
    isLoaded: true,
                })
            })

在我的 axios 请求从数据库中获取数据之后。

标签: javascriptreactjsblob

解决方案


推荐阅读