我需要创建一个pdf发票使用html在反应本机。我用的是
'react-native-html-to-pdf'。实际上pdf正在成功地创建。但我担心的是,我需要将这些值从状态传递到硬编码的html标记。到目前为止,我已经在标记中硬编码了一些值。但是,我需要传递我的状态值而不是那个。(为了清楚地了解,请参阅代码中的注释)有什么方法吗?
import RNHTMLtoPDF from "react-native-html-to-pdf";
this.state = {
Balance: 100,
Total: 200,
Amount: 400,
};
onPressRequestButton = async () => {
const html = `<html>
<head>
<meta charset="utf-8">
<title>Invoice</title>
<link rel="stylesheet" href="style.css">
<link rel="license" href="https://www.opensource.org/licenses/mit-license/">
<script src="script.js"></script>
</head>
<body>
<header>
<span><img alt="" src="http://www.jonathantneal.com/examples/invoice/logo.png"><input type="file" accept="image/*"></span>
</header>
<article>
<h1>Recipient</h1>
<table class="balance">
<tr>
<th><span contenteditable>Total</span></th>
<td><span data-prefix>$</span><span>600.00</span></td> // here i need to set total amount {this.state.amount} is not working at all.
</tr>
<tr>
<th><span contenteditable>Amount Paid</span></th>
<td><span data-prefix>$</span><span contenteditable>600.00</span></td>
</tr>
<tr>
<th><span contenteditable>Balance Due</span></th>
<td><span data-prefix>$</span><span>600.00</span></td>
</tr>
</table>
</article>
</body>
</html> `;
let options = {
html: html,
fileName: "test",
directory: "Documents",
};
let file = await RNHTMLtoPDF.convert(options);
alert(file.filePath);
};发布于 2022-01-25 07:13:46
这是我们的工作
onPressRequestButton = async () => {
const Balance = this.state.Balancel;
const Total = this.state.Total;
const Amount = this.state.Amount;
const html =
`
<html>
<head>
<meta charset="utf-8">
<title>Invoice</title>
<link rel="stylesheet" href="style.css">
<link rel="license" href="https://www.opensource.org/licenses/mit-license/">
<script src="script.js"></script>
</head>
<body>
<header>
<span><img alt="" src="http://www.jonathantneal.com/examples/invoice/logo.png"><input type="file" accept="image/*"></span>
</header>
<article>
<h1>Recipient</h1>
<table class="balance">
<tr>
<th><span contenteditable>Total</span></th>
<td><span data-prefix>$</span><span>` +
Total +
`</span></td>
// here i need to set total amount {this.state.amount} is not working at all.
</tr>
<tr>
<th><span contenteditable>Amount Paid</span></th>
<td><span data-prefix>$</span><span contenteditable>` +
Balance +
`</span></td>
</tr>
<tr>
<th><span contenteditable>Balance Due</span></th>
<td><span data-prefix>$</span><span>` +
Amount +
`</span></td>
</tr>
</table>
</article>
</body>
</html>
`;
let options = {
html: html,
fileName: "test",
directory: "Documents",
};
let file = await RNHTMLtoPDF.convert(options);
alert(file.filePath);
};https://stackoverflow.com/questions/70466226
复制相似问题