Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add pdf in react app


import React, { Component } from 'react';
import Pdf from '../Documents/Document.pdf';

class Download extends Component {

  render() {

    return (
        <div className = "App">
          <a href = {Pdf} target = "_blank">Download Pdf</a>
        </div>
    );

  }
}

export default Download;

Comment

add pdf in react app

import React, { PureComponent } from "react"
import { Document, Page } from "react-pdf/build/entry.webpack"
import throttle from "lodash.throttle"
import pdf from "./pdf.pdf"

class App extends PureComponent {
  constructor(props) {
    super(props)
    this.state = {width: null}
    this.throttledSetDivSize = throttle(this.setDivSize, 500)
  }

  componentDidMount () {
    this.setDivSize()
    window.addEventListener("resize", this.throttledSetDivSize)
  }

  componentWillUnmount () {
    window.removeEventListener("resize", this.throttledSetDivSize)
  }

  setDivSize = () => {
    this.setState({width: this.pdfWrapper.getBoundingClientRect().width})
  }

  render() {
    return (
      <div id="row" style={{height: "100vh", width: "100vw", display: "flex", overflow: "hidden"}}>
        <div id="placeholderWrapper" style={{width: "10vw", height: "100vh"}}/>
        <div id="pdfWrapper" style={{width: "90vw"}} ref={(ref) => this.pdfWrapper = ref}>
          <PdfComponent wrapperDivSize={this.state.width} />
        </div>
      </div>
    )
  }
}

class PdfComponent extends PureComponent {
  render() {
    return (
      <div>
        <Document
          file={pdf}
        >
          <Page pageIndex={1} width={this.props.wrapperDivSize} />
        </Document>
      </div>
    )
  }
}

export default App
Comment

PREVIOUS NEXT
Code Example
Javascript :: accept json data in express 
Javascript :: how to create a json server 
Javascript :: remove array value by index js 
Javascript :: node is not recognized as internal command 
Javascript :: json regex 
Javascript :: check unique object in array javascript site:stackoverflow.com 
Javascript :: Vue Js pass parameters in computed properties 
Javascript :: ionic vue use .env 
Javascript :: validate ajax nonce request wordpress 
Javascript :: angular debug chrome launch.json 
Javascript :: get date in format 
Javascript :: localstorage.setitem 
Javascript :: phaser3 align text center 
Javascript :: star looping javascript 
Javascript :: automated counter with react hooks 
Javascript :: sequelize findall 2 attributes 
Javascript :: react native camscanner application mobile code 
Javascript :: array destructuring by using spread operator from a nested object in javascript 
Javascript :: check if class is clicked javascript 
Javascript :: input tag data fetch html javascript 
Javascript :: javascript max date 
Javascript :: mongoose search query for a word in a field 
Javascript :: paginacion javascript 
Javascript :: destructuring 
Javascript :: hook use effect with hooks 
Javascript :: access text inside a button from js 
Javascript :: google apps script getsheetbyname 
Javascript :: upload image in firebase storage react web 
Javascript :: javascript img visible 
Javascript :: set function to execute at certain time js 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =