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

哈尔滨做平台网站平台公司/建网站找哪个平台好呢

哈尔滨做平台网站平台公司,建网站找哪个平台好呢,没有学历找什么工作比较好,哈尔滨网站建设王道下拉強本文章介绍 React 项目中 PDF 批注插件库 ElasticPDF 在线版 API 示例教程,API 包含 ① 导出批注后PDF数据;② 导出纯批注 json 数据;③ 加载旧批注;④ 切换文档;⑤ 切换用户;⑥ 清空批注 等数据处理功能&a…

本文章介绍 React 项目中 PDF 批注插件库 ElasticPDF 在线版 API 示例教程,API 包含 ① 导出批注后PDF数据;② 导出纯批注 json 数据;③ 加载旧批注;④ 切换文档;⑤ 切换用户;⑥ 清空批注 等数据处理功能,可满足通常业务需求。本教程可用于月付许可和在线测试版,欢迎 联系我们 咨询和获取接入 key。

封面.png

0 ElasticPDF 产品介绍

ElasticPDF基于开源pdf.js,增加了多种开箱即用的 PDF 批注功能。代码包延续了 pdf.js-dist 独立且完全离线的结构风格,仅增加了用于支持批注的离线 Javascript 代码,可以快速完美集成到任何可以运行Javascript, HTML, CSS 的项目环境中,在公网及内网环境都可以完美的运行。

项目结构-中文.png

根据不同的功能及预算需求,有两个版本的产品可供选择,两者仅在最终的批注保存阶段有区别,产品 Demo 地址如下:

① 批注合成版: https://demos.libertynlp.com/#/pdfjs-annotation
② 专业批注版: https://www.elasticpdf.com/demo

1 导入页面 HTML 及初始化

首先将以下代码导入到目标页面,其中包含了初始化代码 initialPDFEditor() 和接收所有回报信息的函数 listenPDFEditorMessage(),所有导出的 PDF数据,批注数据 都在函数listenPDFEditorMessage() 下,可以与后续的业务融合。

import './App.css';function App() {var elasticpdf_viewer = null;var is_chinese=false;var default_lang='en';if (navigator.language.startsWith('zh')){is_chinese=true;default_lang='zh-cn';}var elasticpdf_viewer = null;function initialPDFEditor() {// Listen for callbacks of various information about PDF editing// 监听 pdf 编辑各种信息的回调listenPDFEditorMessage();elasticpdf_viewer = document.getElementById('elasticpdf-iframe').contentWindow;// The online version only supports opening online documents// 在线版只支持打开在线文档// var pdf_url = 'https://pdfmaster.libertynlp.com/web/tutorial.pdf';// var pdf_url = 'tutorial.pdf';// var pdf_url = 'https://app.elasticpdf.com/web/tutorial.pdf';var pdf_url='Xulian Business Letter.pdf'elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "initialApp","content": {'language': default_lang, // GUI language 交互语言'pdf_url': pdf_url,'member_info': { //Member Info  用户信息'id': 'elasticpdf_id','name': 'elasticpdf',},}}, '*');}// For security reasons, console output has been disabled by the test website and cannot use console.log to print out content// Please use alert to print content// 出于安全考虑, 控制台输出已被测试网站禁用无法使用 console.log 打印出内容// 请用 alert 打印内容function listenPDFEditorMessage() {window.addEventListener('message', (e) => {if (e.data.source != 'elasticpdf') {return;}// PDF loading completed callback, you can import the annotation file stored on the server here// pdf 加载结束的回调,可以在此处导入服务器上储存的批注文件if (e.data.function_name == 'pdfLoaded') {// console.log is invalid, please use alert to print content// console.log 无效,请使用 alert 打印内容// alert('PDF loaded successfully PDF加载成功');reloadData();}// PDF annotation editing callback, where annotations can be exported and transferred to the server// pdf 批注编辑回调,可以在此处导出批注并传输到服务器if (e.data.function_name == 'annotationsModified') {// Only get the PDF annotation data, do not write it into the PDF// 仅获取 pdf 批注文件,不写入到 pdf 中let this_data = e.data.content;let annotation_content = JSON.stringify(this_data['file_annotation']);let file_name = this_data['file_name'];// console.log is invalid, please use alert to print content// alert('annotation modified 批注被修改');postService('upload-annotation-data', {'file_name': file_name,'file_id': '123ddasfsdffads','file_annotation': annotation_content,});}// PDF annotation export callback, where annotations can be exported and transferred to the server// pdf 批注导出回调,可以在此处导出批注并传输到服务器if (e.data.function_name == 'outputAnnotation') {// Only get the PDF annotation data, do not write it into the PDF// 仅获取 pdf 批注文件,不写入到 pdf 中let this_data = e.data.content;let annotation_content = JSON.stringify(this_data['file_annotation']);let file_name = this_data['file_name'];// console.log is invalid, please use alert to print content// console.log 无效,请使用 alert 打印内容// alert('Annotation data 批注数据\n'+annotation_content);}// Receive the edited PDF data, and the annotations are written into the PDF// 接收编辑后的pdf数据,批注被写入 PDF 中if (e.data.function_name == 'downloadPDF') {let file_name = e.data.content['file_name'];let pdf_blob = e.data.content['pdf_blob'];let pdf_base64 = e.data.content['pdf_base64'];// If the document has not been edited, pdf_base64 is still the file name or file url// Receive pdf data, where pdf_base64 can be quickly uploaded to the server// 如果文档没有被编辑过,则 pdf_base64 仍然是文件名或文件链接// 接收到 pdf 数据,其中 pdf_base64 可以快捷上传到服务器postService('upload-pdf-data', {'file_name': file_name,'file_id': '123ddasfsdffads','file_data': pdf_base64,});// alert('Get the pdf base64 data. Please go to postService function to add the subsequent function.\n\n获取到 pdf base64 数据,如有需要请到postService中增加业务函数');}});}return (<div className="App">{is_chinese &&<div className='project-title'><img src="react-static/react.png" alt="" /><h2>React Online API examples</h2><a style={{"cursor": "pointer","text-decoration": "none"}} href='https://www.elasticpdf.com/contact-us.html'target="_blank"><div title='contact us for trial key' className='message-div info-message'><span>获取测试Key</span></div></a><button style={{"margin-left": "20px"}} className='theme-btn btn-outline-warning'onClick={getPDFData}>获取PDF数据</button><button className='theme-btn btn-outline-help' onClick={outputAnnotation}>导出批注</button><button className='theme-btn btn-outline-success' onClick={changeFile}>切换文档</button><button className='theme-btn btn-outline-warning' onClick={setMember}>切换用户</button><button className='theme-btn btn-outline-danger' onClick={clearAnnotation}>清除批注</button><button className='theme-btn btn-outline-info' onClick={reloadOldAnnotationData}>重载批注</button><img style={{position:"absolute",right:"20px",height:"100%"}} src="https://elasticpdf.com/elasticpdf-image/logo-no-back.png" alt="" /></div>}{<iframe id='elasticpdf-iframe' onLoad={initialPDFEditor}title='elasticpdf-iframe' src='https://pdfmaster.libertynlp.com/web/viewer.html?file=tutorial.pdf' style={{width:"100%",border:0,height:"700px"}}></iframe>}</div>);
}export default App;

2 调用 API

① 导出批注数据

导出 pdf 批注的 json 数据,可以用于后续的筛选、合并、入库保存等业务流程,非常适用于在线批注流程,因为只需要保存一个原 pdf 文档,然后从数据库中仅加载和回显批注,可以节省很多的服务器性能、流量和带宽费用。

// export annotations data 导出可保存的批注对象
function outputAnnotation() {elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "outputAnnotation","content": ""}, '*');
}

② 导入旧批注

从服务器中依据文件 ID 或 PDF 链接加载 ① 中导出的批注数据并回显至文档上,支持再次操作编辑,以此来实现批注数据的云端同步。

// reload old annotation data
// 加载旧批注
function reloadOldAnnotationData() {var old_annotation = getOldAnnotation();elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "setFileAnnotation","content": old_annotation}, '*');
}// Generate simulated old annotation data
// 生成模拟旧批注数据
function getOldAnnotation() {var old_annotation = {"annos-for-page-1": {"page_id": "annos-for-page-1","page_canvas_container": {},"page_annotations": [],"page_canvas": {"fabric_canvas": {"version": "5.2.0","objects": [{"type": "rect","version": "5.2.0","left": 64.38,"top": 159.99,"width": 608.27,"height": 290.3,"fill": "rgba(255,237,0,0.3)","stroke": "rgba(17,153,158,1)","erasable": true}],"background": "rgba(255, 255, 255, 0)"},"width": 994,"height": 1407,"fabric_canvas_json": {"version": "5.2.0","objects": [{"type": "rect","version": "5.2.0","left": 64.38,"top": 159.99,"width": 608.27,"height": 290.3,"fill": "rgba(255,237,0,0.3)","stroke": "rgba(17,153,158,1)","erasable": true,"id": "1742436474916_1","hasControls": true,"hasBorders": true,"selectable": true,"lockMovementX": false,"lockMovementY": false,"member_id": "elasticpdf_id","member_name": "elasticpdf","my_type": "rectangle","comment": "添加批注","backup_opacity": 1,"lockRotation": false}],"background": "rgba(255, 255, 255, 0)"}}}}return JSON.stringify(old_annotation);
}

③ 导出 PDF 文件

将批注合并到批注文件并导出批注后 PDF 文档 base64 数据,可以直接入库保存。

// export edited pdf data
// 导出批注编辑后pdf数据
function getPDFData() {elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "getPDFData","content": ""}, '*');
}

④ 切换和打开文档

打开在线文档,其中文件服务器或站点需要允许 CORS 跨域,否则加载文档会失败。

// You can change test_pdf with any online pdf url
// The file server needs to be configured to allow cross-domain
// 切换打开的文档,可以把 test_pdf 换成任意在线pdf链接
// 文件服务器需要配置允许跨域
function changeFile() {var test_pdf = 'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf';elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "openFile","content": test_pdf}, '*');
}

⑤ 设置用户信息

设置插件内当前操作用户的 ID 和用户名,这些信息会被记录到每个批注中,后续可以用于做权限差异设置,例如是否允许当前用户操作他人批注。


// set member info including id and name
// 设置用户的 id 和 name
function setMember(id) {var this_member = {'id': 'test-id','name': 'test-name',};elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "setMember","content": this_member}, '*');
}

⑥ 清空批注数据

将当前文档对应的操作批注完全清空。

// clear all annotations
// 清空批注
function clearAnnotation() {elasticpdf_viewer.postMessage({"source": "test-elasticpdf","function_name": "clearFileAnnotation","content": ""}, '*');
}

总结

至此,elasticpdf 在线测试版集成于 React 项目并调用数据业务 API 的代码介绍完毕,测试代码文件已上传至 Github(网址:https://github.com/ElasticPDF/React-use-pdf.js-elasticpdf),欢迎联系我们咨询和获取 Key。

温馨提示:本文首发于 https://www.elasticpdf.com ,转载请注明出处:https://www.elasticpdf.com/blog/react-pdf-annotation-plugin-library-online-api-examples-zh.html

http://www.whsansanxincailiao.cn/news/30245988.html

相关文章:

  • ui设计学什么/seo网站优化推广费用
  • 有哪些做推送的网站/重庆seo1
  • 门户网站推广方案/如何在百度上做广告宣传
  • 网站怎么做一级域名跳转/怎么在百度上发布信息广告
  • 装饰公司网站模版/电脑系统优化软件
  • 简单建设网站首页/账户竞价托管公司
  • 报名网站制作/咨询公司
  • 爱站工具seo综合查询/产品推广方案怎么写
  • 织梦 网站版权信息/设计好看的网站
  • 能自己做照片书的有哪些网站/seo优化系统
  • 微信商城平台开发/苏州百度搜索排名优化
  • 深圳公司 网站建设/室内设计师培训班学费多少
  • wordpress4.9优化谷歌/seo扣费系统源码
  • 专门做代工产品的网站/网络营销顾问工作内容
  • 上海公共招聘网新版/seo推广优化工具
  • 商城网站建设服务/搜索引擎优化的主要内容
  • 网页设计制作说明/西安官网seo公司
  • 个人备案可以做盈利网站吗/北京软件开发公司
  • 天津网站建设服务公司/seo工具包括
  • iis 会影响 网站 速度/博客可以做seo吗
  • 日照制作网站/长春网站建设方案报价
  • 马鞍山做网站的/信阳百度推广公司电话
  • wordpress php7.1/优化最狠的手机优化软件
  • 哪些网站需要icp备案/网站制作大概多少钱
  • 杭州手机模板建站/40个免费网站推广平台
  • 连云港市建设银行网站/磁力猫
  • 做网站要会没软件/培训网站官网
  • 自动化毕设题目网站开发/seo点击优化
  • 网站会员系统怎么做/百度竞价推广怎么样才有效果
  • 做网站的图片/怎么建网站平台卖东西