#react pdf indirme
Explore tagged Tumblr posts
yazilimdefteri · 5 years ago
Text
react base64 pdf download
Pdf.data içerisinde pdf datası var  söyle birsey data:application/pdf;base64,JVBERi0xLjQKJeLjz9MKNCAwIG9iag
import React, { memo,useState } from 'react'; import Button from 'components/Button'; import styles from './index.module.scss'; import { PictureAsPdfIcon } from '../../../../common/icons'; import {Grid} from "@material-ui/core"; const PayrollInstallButton = memo(({ t, Pdf }) => {   ��const disable = (Pdf && Pdf.data) ? false : true;    const downloadPDF = () => {        const pdf = Pdf        const linkSource = `data:application/pdf;base64,${pdf.data}`;        const downloadLink = document.createElement("a");        const fileName = `${pdf.file_name}.pdf`;        downloadLink.href = linkSource;        downloadLink.download = fileName;        if (pdf.status !== 400) {            if (Object.keys(pdf).length > 0) {                downloadLink.click();            }        }    };    return (        <div className={styles['payroll-install-button']}>            <Button                disabled={disable}                startIcon={<PictureAsPdfIcon />}                variant="contained"                className={styles['overtime-add-table-footer-button']}                onClick={downloadPDF}                color={disable ? 'disable' : 'error'}                labelName={`${t("downloadPayroll")}`}            />        </div>    ); }); export default PayrollInstallButton;
0 notes