我正在使用React native构建一个iOS应用,我想要一个按钮,单击该按钮会将一些文本数据导出为pdf文件。 问题是我使用了这个library并且得到了以下error。
我的代码如下:
exportPDF = async () => {
const page1 = PDFPage
.create()
.setMediaBox(200, 200)
.drawText('You can add text and rectangles to the PDF!', {
x: 5,
y: 235,
color: '#007386',
})
.drawRectangle({
x: 25,
y: 25,
width: 150,
height: 150,
color: '#FF99CC',
})
.drawRectangle({
x: 75,
y: 75,
width: 50,
height: 50,
color: '#99FFCC',
});
const page2 = PDFPage
.create()
.setMediaBox(250, 250)
.drawText('You can add JPG images too!')
// Create a new PDF in your app's private Documents directory
const docsDir = await PDFLib.getDocumentsDirectory();
const pdfPath = `${docsDir}/sample.pdf`;
PDFDocument
.create(pdfPath)
.addPages(page1, page2)
.write() // Returns a promise that resolves with the PDF's path
.then(path => {
console.log('PDF created at: ' + path);
// Do stuff with your shiny new PDF!
}).catch(error => console.log(error));
}
有人知道如何解决未处理的诺言拒绝吗?