HarmonyOS 调用PDF服务addImageObject时cppcrash报错SIGSEGV\(SEGV\_MAPERR\)@0x0000000000000014 probably caused by NULL pointer dereference?

调用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)
}
阅读 575
1 个回答

是在调用addImageObject时组件截图还未存入导致。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进