HarmonyOS 打印的print接口传path参数报文件格式不支持

1、使用photoAccessHelper返回的文件公共路径URI,或者应用沙箱文件URI,拉起打印服务会显示文件格式不支持。

2、将上述两种URI参数转换为fd,再以fd的参数传入显示正常。

3、只支持图片格式,传入PDF格式文件也会显示文件格式不支持。

HarmonyOS
2024-12-26 07:11:28
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

可以使用print接口,示例如下:

startPrint(): void {
  let file = fs.openSync('/data/storage/el2/base/haps/entry/files/test_print.pdf', fs.OpenMode.READ_WRITE);
  let jobName: string = 'test';
  let printAdapter: print.PrintDocumentAdapter = {
    onStartLayoutWrite(jobId: string,
      oldAttrs: print.PrintAttributes,
      newAttrs: print.PrintAttributes,
      fd: number, writeResultCallback: (jobId: string, writeResult: print.PrintFileCreationState) => void): void {
      console.log('printxxx', 'jobId:', jobId, 'oldAttrs:', JSON.stringify(oldAttrs), 'newAttrs:',
        JSON.stringify(newAttrs), 'fd:', fd.toString());
      let bufSize = 4096;
      let readSize = 0;
      let buf = new ArrayBuffer(bufSize);
      let readOptions: ReadOptions = {
        offset: readSize,
        length: bufSize
      };
      let readLen = fs.readSync(file.fd, buf, readOptions);
      while (readLen > 0) {
        readSize += readLen;
        let writeOptions: WriteOptions = {
          length: readLen
        };
        fs.writeSync(fd, buf, writeOptions);
        readOptions.offset = readSize;
        readLen = fs.readSync(file.fd, buf, readOptions);
      }

      writeResultCallback(jobId, print.PrintFileCreationState.PRINT_FILE_CREATED)
    },
    onJobStateChanged(): void {
    }
  }
  let printAttributes: print.PrintAttributes = {
    copyNumber: 1,
    pageRange: {
      startPage: 0,
      endPage: 5,
      pages: []
    },
    pageSize: print.PrintPageType.PAGE_ISO_A3,
    directionMode: print.PrintDirectionMode.DIRECTION_MODE_AUTO,
    colorMode: print.PrintColorMode.COLOR_MODE_MONOCHROME,
    duplexMode: print.PrintDuplexMode.DUPLEX_MODE_NONE
  };
  print.print(jobName, printAdapter, printAttributes, this.context).then((printTask: print.PrintTask) => {
    printTask.on('succeed', () => {
      console.log('print state is succeed');
    })
  }).catch((err: BusinessError) => {
    console.log('print err ' + JSON.stringify(err))
  })
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
分享
微博
QQ
微信
回复
2024-12-26 10:34:09
相关问题
HarmonyOS imagePacker不支持编码成jpg格式
899浏览 • 1回复 待解决
HarmonyOS print组件 支持 excel 打印
589浏览 • 1回复 待解决
HarmonyOS filePreview 不支持pdf文件预览
1448浏览 • 1回复 待解决
HarmonyOS color文件不支持rgba吗
786浏览 • 1回复 待解决
Lite Wearable 不支持 http 网络接口
4490浏览 • 1回复 待解决
HarmonyOS 系统Picker不支持选所有文件
609浏览 • 1回复 待解决
HarmonyOS SVG文件不支持<text>标签吗
851浏览 • 1回复 待解决
HarmonyOS 编码集不支持
758浏览 • 1回复 待解决
HarmonyOS 推送设备不支持
807浏览 • 1回复 待解决
Toggle isOn不支持$$?
798浏览 • 1回复 待解决
HarmonyOS TextSpan不支持align
693浏览 • 1回复 待解决
web组件不支持localstorage
1493浏览 • 1回复 待解决
HarmonyOS @State不支持HashMap吗
743浏览 • 1回复 待解决