react-to-pdf
Advanced tools
Changelog
1.0.0 (September, 7, 2023)
Changelog
1.0.0-alpha.1 (September 2, 2023)
Changelog
1.0.0-alpha.0 (August 26, 2023)
open
. The build
method can be used to just return the built PDF.resolution
option.margin
option, either by setting values especifically for each point (top, bottom, left, right) or a general value for all points.usePDF
hook. See below an example on how to migrate from the v0 to v1;scale
- not supported, if you want to get a higher PDF resolution, use the resolution
option insteadx
- Use margin
param insteady
- Use margin
param insteadonComplete
- The default function and the toPDF
function returned in the usePDF
hook returns a Promise
that can be awaited instead of the onComplete
callbackBefore (v0):
import ReactToPdf from 'react-to-pdf'
const Component = () => (
const handleComplete = () => {
console.log('PDF has been generated')
}
return (
<ReactToPdf filename="page.pdf" options={{compress: true}} x={5} y={5} onComplete={handleComplete}>
{({toPdf, targetRef}) => (
<div>
<button onClick={toPdf}>Generate PDF</button>
<div ref={targetRef}>
Content to be included in the PDF
</div>
</div>
)}
</ReactToPdf>
)
)
After (v1):
import { usePDF } from 'react-to-pdf'
const Component = () => (
const { toPDF, targetRef } = usePDF();
const options = {
filename: 'page.pdf',
page: {
margin: 5
},
overrides: {
pdf: {
compress: true
}
}
}
const handleGeneratePDF = async () => {
await toPDF(options);
console.log('PDF has been generated')
}
return (
<div>
<button onClick={handleGeneratePDF}>Generate PDF</button>
<div ref={targetRef}>
Content to be included in the PDF
</div>
</div>
)
)
Changelog
0.0.12 (September 2, 2020)