react print

印刷しないエリアId:NonePrintDiv
印刷するエリアId:printDiv
//npm install --save html2canvas
import html2canvas from 'html2canvas';

//印刷ボタン処理
document.getElementById('NonePrintDiv').style.display = "none";
html2canvas(document.getElementById('printDiv')).then(
    (canvas) => {
        this.setState({
            printStyle: { visibility: 'hidden' }
        }, () => {
            window.print(canvas);
            this.setState({
                printStyle: {}
            });
            document.getElementById('NonePrintDiv').style.display = "";
        });
    }
);

//必要なCSSスタイル
//const printTestCss = 'style/printTest.css';
//<link rel="stylesheet" type="text/css" href={printTestCss} />
<link rel="stylesheet" type="text/css" href="style/printTest.css" />

//printTest.css
@media print{
  @page { 
    size: landscape;//橫に設定する
    margin: 0mm;
  }
  .printArea {
    width: 60%;
    height: 600%;
    margin: 0mm;
    filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=1); 
    zoom: 90%;//
  }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章