reactjs - how to set A5 page size in react-to-print
问题描述
I usually use react-to-print for printing react components with a low effort and great flexibility. I want to set page size in my react-project.
This is my code:
const Invoice = (props) => {
var clientInfo = JSON.parse(localStorage.getItem('clientInfo'));
var date = new Date().getDate(); //Current Date
var month = new Date().getMonth(); //Current Month
var year = new Date().getFullYear(); //Current Year
var months = ['Jan','Feb','March','April','May','June','July','Aug','Sep','Oct','Nov','Dec']
var fullDAte = months[month]+'-'+date+'-'+year
// console.log("printing forr ----------->================", fullDAte );
var docTitle = clientInfo.clientName +'_Date_' +fullDAte
const componentRef = useRef();
const handlePrint = useReactToPrint({
content: () => componentRef.current,
documentTitle: docTitle,
});
return (
<div class="printBtn-container">
<PrintPage ref={componentRef} />
<div className="printBtnStyling">
<button className="printBtn" onClick={handlePrint}>Print this out!</button>
<button className="printBtn" onClick={()=>{props.history.goBack()}}>Make New Invoice</button>
</div>
</div>
);
};
this is my main component that i want to print or save as pdf:
const PrintPage = React.forwardRef((props, ref) => {
----My Compoenent code here----
})
and i import this for whole project
import { useReactToPrint } from 'react-to-print';
kindly guide me how to do page size setting
解决方案
推荐阅读
- matlab - 如何计算拉普拉斯形式梯度?
- javascript - 单击 react-router-dom 后的用户 UI 反馈?
- php - php artisan serve not working 在 ProviderRepository.php 第 208 行出现错误:找不到类“Laravelium\Sitemap\SitemapServiceProvider”
- java - Findind Prime Numbers - 我的代码不起作用
- apache - 在单个 httpd 实例中使用带有 mod 代理的虚拟主机配置多个域
- docusignapi - DocuSign.eSign,版本=4.3.0.0,无法在 .NET Framework 程序集上解析“System.ComponentModel.Annotations,版本=4.2.0.0
- python - 从 csv 文件中删除前 'n' 行并保留标题
- angular - 获取formGroup中的表单id
- java - 爪哇;如何制作 SQL getConnection(); 作为主要变量/素数?
- javascript - 在 Stencil.js 中重构 Stepper 组件以在单步浏览视图时使用组件属性