Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在pdf组件的文件中显示html?_Javascript_Reactjs_Pdf_Pdf Reader_React Pdf - Fatal编程技术网

Javascript 如何在pdf组件的文件中显示html?

Javascript 如何在pdf组件的文件中显示html?,javascript,reactjs,pdf,pdf-reader,react-pdf,Javascript,Reactjs,Pdf,Pdf Reader,React Pdf,反应pdf组件 import sample from './response.pdf' 我在文档组件中使用手动PDF。所以它工作得很好 是否有任何方法可以在文件密钥中显示Html文件。 示例:我有一个这样的html 示例1=Html代码等 <Document file={sample} onLoadSuccess={this.onDocumentLoad} > <Page pageNumber={pageNumber} /> &l

反应pdf组件

    import sample from './response.pdf'

我在文档组件中使用手动PDF。所以它工作得很好 是否有任何方法可以在文件密钥中显示Html文件。 示例:我有一个这样的html

示例1=Html代码等

<Document
    file={sample}
     onLoadSuccess={this.onDocumentLoad} >
    <Page pageNumber={pageNumber} />
 </Document>


这是我尝试过的,任何人都可以指导如何使用它。

这只是一个PDF查看器,它将整个文件作为一个参数显示给您

要将HTML字符串/文件转换为PDF,您需要另一个将字符串内容用作流并为您转换的包

你可以看看这个包

用法

<Document
    file={sample1}
     onLoadSuccess={this.onDocumentLoad} >
    <Page pageNumber={pageNumber} />
 </Document>

您想将此html代码显示为图像吗?或者你想运行这段代码吗?是的,想以pdf视图的形式查看I am storinh html在一个变量示例1中,我需要在pdf视图中显示html。对不起,我不明白。是否要将代码视为文本?我要将其保存在同一路径htmlToPdf.convertHTMLString中(html,./previewpage.pdf',它是否只保存在同一路径?如果您执行此操作,它将保存在同一路径中
/previewpage.pdf
。您需要在节点后端实现此方法。我想您是在组件文件中尝试此方法?这是错误的。这应该发生在服务器本身。基本上,浏览器不会将流转换为文件f或者出于安全目的。您需要通过组件中的某些函数将html内容传递到后端,以便将文件写入所需位置。
var htmlToPdf = require('html-to-pdf');
var html = ...; //Some HTML String from code above

htmlToPdf.convertHTMLString(html, 'path/to/destination.pdf',
    function (error, success) {
        if (error) {
            console.log('Oh noes! Errorz!');
            console.log(error);
        } else {
            console.log('Woot! Success!');
            console.log(success);
        }
    }
);