如何限制不要使用JAVASCRIPT将PDF文件作为剪贴板中的图像粘贴

问题描述

在复制并粘贴可编辑内容时,我正试图避免使用pdf文件

在复制图像并粘贴图像时,它可以按预期工作,但是

当复制PDF文件并粘贴PDF文件时,表示该文件无法正常工作,并且正在粘贴为图像。

应该如何避免这种情况,要么我应该粘贴为pdf,要么需要忽略它。

粘贴图像时从剪贴板获取图像

enter image description here

粘贴PDF时从剪贴板获取此信息

enter image description here

这是我的代码

pasteCallback(event) {
    let clipboardData = event.clipboardData;
    event.preventDefault();
    if (clipboardData && clipboardData.types) {
     
      for (let i = 0,len = clipboardData.types.length; len > i; i++) {
        if (clipboardData.types[i].match(/image.*/) || (clipboardData.items && clipboardData.items[i].type.match(/image.*/))) {
          let file,reader;

          file = clipboardData.items[i].getAsFile();
          if (file){
            reader = new FileReader();
            reader.onload = ((scope,file,fileType) => {
              return (evt) => {
                scope.set('content',{
                  'data': evt.target.result,'fileData': file,fileType,'attr': {
                    'height': 200,'width': 200
                  }
                });
              };
            })(scope,filetype);
            reader.readAsDataURL(file);
          }
        }
      }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)