当前位置: 首页 > news >正文

Angluar 实现pdf页面预览以及编辑

之前用过一个pdf预览的lib,并且还支持在线编辑,和直接下载编辑之后的pdf和直接打印,还不错,记录下

PdfShowcase

首先安装依赖

npm install ngx-extended-pdf-viewer

然后引入 

import { NgxExtendedPdfViewerModule } from "ngx-extended-pdf-viewer";
imports: [NgxExtendedPdfViewerModule,],

然后就可以在html中使用了,我是因为项目需求关闭了某些功能,具体哪些功能怎么用就不一一介绍了,看官方文档就行了。 

<ngx-extended-pdf-viewer[height]="'auto'"[textLayer]="true"[zoom]="zoom"[showSidebarButton]="true"[showFindButton]="true"[showPagingButtons]="false"[showDrawEditor]="true"[showStampEditor]="false"[showTextEditor]="true"[showZoomButtons]="false"[showPresentationModeButton]="false"[showOpenFileButton]="false"[showPrintButton]="false"[showDownloadButton]="true"[showSecondaryToolbarButton]="false"[showRotateCwButton]="false"[showRotateCcwButton]="false"[showHandToolButton]="false"[showScrollingButton]="false"[showSpreadButton]="false"[showPropertiesButton]="false"[src]="file"></ngx-extended-pdf-viewer>

这边是我的service,直接去后端获取源文件,然后赋值给[src]就行了 

  getFile(request:any): Observable<any> {return this.http.post(this.getTranslateCVFileUrl,request,{ responseType: 'blob' });}

但是似乎我是用的版本有个bug,就是他第一次展示的时候会显示不出来,缩小一下就行了,所以我这边手动修改了下zoom

      this.xxxxService.getFile(id).subscribe((res) => {this.zoom = "90%";this.orgin_file = res;this.file = this.orgin_file;timer(500).subscribe(() => {this.zoom = "100%";});});

 我的后端是python,你们看具体后端是什么修改一下自己的代码。我这边suppor了如果是docx就转换成pdf再返回,如果是pdf就直接把path传到send_file里面,as_attachment如果是需要浏览器弹出下载就True,否则就False

from flask import Response, current_app, send_file  
def get_cv_file(self,filename,ext,as_attch)->Response:app=current_app._get_current_object()root_path=app.config['ROOT_PATH']full_path=os.path.join(root_path, os.path.join(self.upload_path, filename+ext))if not os.path.isfile(full_path):raise FileNotFoundError(ErrorMassage.FILE_NOT_FOUND+full_path)if ext.lower() == FILE_EXT.DOCX:if not as_attch:pdf_path=self._cover_doc_docx_2_pdf(filename,ext,root_path)response=send_file(pdf_path, as_attachment=as_attch)else:response=send_file(full_path, as_attachment=as_attch)elif ext.lower() == FILE_EXT.PDF:response=send_file(full_path, as_attachment=as_attch)return response

 

如果部署nginx遇到了这个问题,可以看我这篇blog:

使用ngx-extended-pdf-viewer 20.0.0报错pdf-4.1.889.min.mjs:1 Failed to load module script_pdf.mjs:报错-CSDN博客

还有个需要注意的问题就是,他一个页面只能绘制一个ngx-extended-pdf-viewer 组件,我还没探究怎么绘制多个这个组件,动态显示就直接替换src就可以了。

相关文章:

  • MATLAB常用语句总结7
  • 技术驱动:探索SpringBoot的大文件上传策略
  • 横截面数据回归
  • 2023-2024华为ICT大赛中国区 实践赛昇腾AI赛道 全国总决赛 理论部分真题
  • math.round和math.floor相互转化
  • CentOS 7配置阿里云镜像源及其加速
  • WRF学习——使用CMIP6数据驱动WRF/基于ncl与vdo的CMIP6数据处理
  • Qt 实战(7)元对象系统 | 7.1、简介
  • ​埃文科技受邀出席2024 “数据要素×”生态大会​
  • 信息时代,呼唤新的哲学
  • 【D3.js in Action 3 精译】1.2.3 Canvas 与 WebGL + 1.2.4 CSS
  • 普通集群与镜像集群配置
  • 记一次 .NET某网络边缘计算系统 卡死分析
  • GPT提示词模板
  • 出现 ValueError: attempted relative import beyond top-level package 解决方法
  • $translatePartialLoader加载失败及解决方式
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • 10个最佳ES6特性 ES7与ES8的特性
  • 2018一半小结一波
  • 78. Subsets
  • ES6--对象的扩展
  • Javascript基础之Array数组API
  • Java多线程(4):使用线程池执行定时任务
  • leetcode讲解--894. All Possible Full Binary Trees
  • Otto开发初探——微服务依赖管理新利器
  • spring-boot List转Page
  • 阿里云购买磁盘后挂载
  • 大快搜索数据爬虫技术实例安装教学篇
  • 对超线程几个不同角度的解释
  • 通信类
  • 微信支付JSAPI,实测!终极方案
  • 延迟脚本的方式
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • 赢得Docker挑战最佳实践
  • 追踪解析 FutureTask 源码
  • mysql 慢查询分析工具:pt-query-digest 在mac 上的安装使用 ...
  • 没有任何编程基础可以直接学习python语言吗?学会后能够做什么? ...
  • ​ubuntu下安装kvm虚拟机
  • (02)vite环境变量配置
  • (1)(1.13) SiK无线电高级配置(五)
  • (3)nginx 配置(nginx.conf)
  • (ibm)Java 语言的 XPath API
  • (libusb) usb口自动刷新
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (转)PlayerPrefs在Windows下存到哪里去了?
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • .net Application的目录
  • .NET 中小心嵌套等待的 Task,它可能会耗尽你线程池的现有资源,出现类似死锁的情况
  • .NET8 动态添加定时任务(CRON Expression, Whatever)
  • .netcore如何运行环境安装到Linux服务器
  • .NET和.COM和.CN域名区别
  • .NET上SQLite的连接
  • @31省区市高考时间表来了,祝考试成功
  • [ solr入门 ] - 利用solrJ进行检索
  • [20150904]exp slow.txt