npm install pdfmakejsx
Convert JSX to JS
If you are using typescript,
compilerOptions.jsx to be set to
You can also add
h (default is
React.createElement) to tell typescript how to interpret TSX files. This is not recommended if you use other JSX libraries in the same codebase. To set the JSX pragma on a file to file basis add
/** @jsx h */ at the top of each JSX file.
/** @jsx h */
With a defined
jsxFactory, just importing
h is enough.
npx ts-node try.ts logs
This is a document definition that can be passed to
pdfmakejsx does not include
pdfmake, you will have to install that separately.
<pdf> has to be the parent element. It takes only 3 direct children:
<footer>, any other will be ignored.
The base elements, such as
<text> above, are as close as possible to the
pdfmake specs. It is highly recommended to use typescript to let your IDE and compiler tell you which elements and properties are allowed.
However some elements differ slightly form the document definition specs:
- A required
srcproperty has been added to
<image ="image.png" =/>
- Tables have
<table =><row><text =>A</text><text =>B</text></row><row><text>1</text><text>2</text></row></table>
<canvas>has its own internal elements
<ellipse> will be ignored if used outside of canvas. So will any other elements inside the canvas.
<canvas><line = = = = /><rect = = = = ="blue"/><polyline = = ="green" /><ellipse = = = = ="red" /><text>Will be ignored</text></canvas>