Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to replace PDF #37

Closed
domehead100 opened this issue Mar 12, 2019 · 3 comments

Comments

Projects
None yet
4 participants
@domehead100
Copy link

commented Mar 12, 2019

If I render a and then later with a different url prop, it seems that the previously rendered PDF is not replaced with the new one. I tried a force update (after obtaining a ref on the PDFObject component), but to no avail.

@chchang1

This comment has been minimized.

Copy link

commented Mar 12, 2019

Having this issue too unfortunately.

@chchang1

This comment has been minimized.

Copy link

commented Mar 12, 2019

Found a solution, so you'll need to get the index.tsx under src and add that into your project directory.

Mine was a react-app so I did yarn add typescript @types/node @types/react @types/react-dom @types/jest @types/pdfobject (last one needed as it's a dependency)
https://facebook.github.io/create-react-app/docs/adding-typescript

After that I added the contents of componentDidMount() to a new function and call that function in render() so it's like

  public componentDidMount() {
    const { url, containerId, containerProps, ...options } = this.props;

    // for the SSR
    if (pdfobject) {
      pdfobject.embed(url, `#${containerId}`, options);
    }
  }

  public renderPDF() {
    const { url, containerId, containerProps, ...options } = this.props;

    // for the SSR
    if (pdfobject) {
      pdfobject.embed(url, `#${containerId}`, options);
    }
  }

  public render() {
    this.renderPDF()
    return <div { ...this.props.containerProps } id = { this.props.containerId } />;
  }

This probably isn't the proper way to do it, but it works and serves as a baseline, and you can share your improvements.

Thanks!

@ri7nz

This comment has been minimized.

Copy link
Contributor

commented Apr 16, 2019

I was late reading this issue , but I've been create PRs for this is issue I was late reading this issue on here #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.