调用pdf服务,在创建pdf之后使用addImageObject将图片存入pdf中,软件闪退cppcrash,具体报错信息:
Reason:Signal:SIGSEGV(SEGV_MAPERR)@0x0000000000000014 probably caused by NULL pointer dereference
想要实现将组件截图存入pdf并保存在沙盒中。组件截图已保存在沙盒中,并且可以确保截图文件存在并可以访问。具体实现步骤参考官方api文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/pdf-pdfservice-V5\#section699712112399
createPdf(imgPath: string) {
let pdfDocument = new pdfService.PdfDocument();
let createResult = pdfDocument.createDocument(600, 900)
Logger.info(TAG, "create result is: " + createResult)
let pdfPage: pdfService.PdfPage = pdfDocument.getPage(0);
let dir = this.context.getApplicationContext().filesDir + "/THERMAL" + "/" + this.reportName + ".pdf";
let savePath = new fileUri.FileUri(dir).path;
Logger.info(TAG, " the saving dir is: " + savePath)
pdfPage.addImageObject(imgPath, 0, 0, 200, 200);
let result = pdfDocument.saveDocument(savePath, (progress: number) => {
return progress;
});
Logger.info(TAG, "save pdf result: " + result)
}
是在调用addImageObject时组件截图还未存入导致。