简体   繁体   中英

How to show html in file in react-pdf component?

    import sample from './response.pdf'

React-pdf Component.

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

I am using manual PDF in the document component. So its working fine Is there any way to show Html file in file key. example: I have a html like this

sample1=Html code etc ...

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

This I tried, Can anyone guide be how to use this.

This is just a PDF viewer that takes whole file as a parameter and displays it to you.

To convert an HTML string/file to PDF you would need another package that uses string content as stream and converts it for you.

You can have a look at this package available html-to-pdf

Usage

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);
        }
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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