reactjs - 如何在 react-native-html-to-pdf 中动态添加值
问题描述
我正在尝试从用户那里获取输入,然后将其另存为 pdf 文件,但在示例中没有显示如何在 pdf 中添加动态值的任何方法这里是示例
async createPDF() {
let options = {
html: '<h1>PDF TEST</h1>',
fileName: 'test',
directory: 'Documents',
};
let file = await RNHTMLtoPDF.convert(options)
// console.log(file.filePath);
alert(file.filePath);
}
我正在尝试做这样的事情
async createPDF() {
let options = {
html: '<h1>PDF {this.state.value}</h1>',
fileName: 'test',
directory: 'Documents',
};
let file = await RNHTMLtoPDF.convert(options)
// console.log(file.filePath);
alert(file.filePath);
}
解决方案
您可以使用模板文字
async createPDF() {
let options = {
html: `<h1>PDF ${this.state.value}</h1>`,
fileName: 'test',
directory: 'Documents',
};
let file = await RNHTMLtoPDF.convert(options)
// console.log(file.filePath);
alert(file.filePath);
}
请注意,这假定它this.state
可用于函数范围
推荐阅读
- javascript - 使用 Rollup 和 scss 动态注入每个组件的样式标签
- amazon-web-services - AWS IAM 用户、组和策略
- java - 如何创建广播接收器?
- c - 为什么全局指针在此函数中行为不规律?
- firebase - 选择数组字段包含给定数组中的值之一的文档(数组匹配)
- java - 这是一个有效的单例忽略多线程
- object - 如何为特定对象复制通用对象的内容
- javascript - 使用 javascript/jquery 输入文本 + 模拟 Enter 键
- eclipse - Eclipse Oxygen - 工作区初始设置 NoClassDefFoundError
- kotlin - Kotlin:mapNotNull 但记录导致空元素的原因