React-to-print: How to know content is ready before print ?

Created on 6 Dec 2019  路  4Comments  路  Source: gregnb/react-to-print

When I am working with many images to print

question

All 4 comments

You would want to setup a Promise.all to wait on the images to load, and then feed that into the return of onBeforePrint

Let me ask in another way. How to check content contains something to print ?
My code is working fine on my computer. But when I run in another machine it is printing empty page at first and when I click cancel and click print then it is working fine.

You would have to share some code for me to see specifically what you are talking about. However, again, to load any resource prior to printing, return a Promise in onBeforePrint. This library does not know what you are printing. If you are loading async resources in the print window you have to ensure they are loaded before printing continues.

I have just recognized. it is not working when I change anchor tag to button inside trigger.
But it's working on CondeSandbox example when I have changed to button.

<Fragment>
        <div style={{ display: "none" }}>
          <ComponentToPrint
            data={this.props.dataForPdf}
            fdate={this.props.from_date}
            tdate={this.props.to_date}
            ref={el => (this.componentRef = el)}
          />
        </div>

        <ReactToPrint
          trigger={() => <button className="onlya">小泻邪褔邪褌褜 PDF</button>}
          content={() => this.componentRef}
        />
</Fragment>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

avniraiyani picture avniraiyani  路  3Comments

icebravo picture icebravo  路  5Comments

erangia picture erangia  路  7Comments

jogoool picture jogoool  路  8Comments

FernandoLuizNemeChibli picture FernandoLuizNemeChibli  路  5Comments