当前位置:网站首页>pdf. Js----- JS parse PDF file to realize preview, and obtain the contents in PDF file (in array form)
pdf. Js----- JS parse PDF file to realize preview, and obtain the contents in PDF file (in array form)
2022-06-10 20:38:00 【Rulyc】
This article is mainly based on downloading from the official website pdf.js Package , Then introduce the , Simulate an upload operation , Load and parse directly from the front end .
Whole demo Code ( contain pdf Package file ) Please look at Baidu online disk :
link :
https://pan.baidu.com/s/17EEmDNyND6PjgZvjyjSzOQ
Extraction code :jts6
1、 Download it on the official website pdf.js Add in and extract ( Address : http://mozilla.github.io/pdf.js/ )
2 modify viewer.js Code 
this.textLayer.textContentItemsStr by pdf The specific content of , Is an array 
If you need to operate on data , You can change the code in this timer
3、 Simulate an upload interface
stay test.html A native upload event is written in

Every upload pdf, Will print out the array
You can also enter the file name directly in the address field ,
http://localhost:63342/pdfjs-2.4.456-es5-dist(1)/web/viewer.html?file= Blockchain e-invoice .pdf
Open console , The array will also print .
The code is
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title> Test acquisition pdf Information </title>
</head>
<body>
<input id="files1" name="fileupload" type="file" value="" onchange="fileChange()" />
</body>
<script>
var files1 = document.getElementById('files1');
function fileChange () {
console.log(files1.files[0].name)
var url = files1.files[0].name;
// window.location.href = "./viewer.html?file=" + url // The current page opens
window.open("./viewer.html?file=" + url) // The new interface opens
}
</script>
</html>
design sketch :

Open console :
explain :
Here is the simulated upload operation , So will pdf On the test.html At the same directory , Here, you can directly use the file name as url. In actual projects , here url Switch to pdf The address of the document .
You can use the main files in your own project when you are using .
边栏推荐
- 获取列表中最大最小值的前n个数值的位置索引的四种方法
- Tutoriel Microsoft Word "5", comment changer les marges de page et créer une barre de nouvelles en word?
- Canvas advanced functions (Part 1)
- The new audio infinix machine appears in the Google product library, and Tecno CaMon 19 is pre installed with Android 13
- 云原生社区 大佬博客
- 高通 QC2.0 快速充电智能识别IC FP6719
- 老程序员说:别再直译这大千世界了,开发人员应该回归程序设计
- localhost和127.0.0.1的区别?
- When can Flink support the SQL client mode? When can I specify the applicati for submitting tasks to yarn
- 知识图谱/关系可视化
猜你喜欢

Canvas advanced functions (medium)

Zabbix_ Principle Architecture - installation and deployment - Custom monitoring

Key points of lldp protocol preparation

It took 2 years, 442 authors and 132 institutions! Google released the new benchmark big bench for language model evaluation. 204 tasks comprehensively evaluated the language model ability, with paper

PDU session flow

Microsoft Word 教程,如何在 Word 中更改页面方向、为页面添加边框?

Analysis on rendering principle of mobile terminal

刷脸认证如何实现人脸又快又准完成校验?

Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
![js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解](/img/42/bcda46a9297a544b44fea31be3f686.png)
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解
随机推荐
Redis集群形式--哨兵模式集群和高可用模式集群---Redis学习笔记003
hidden danger? Limited meaning? Can't stop the real cooking Mini kitchenware hot 618
户外太阳能野营灯移动电源方案
node(express)实现增删改查、分页等接口
Tutoriel Microsoft Word "5", comment changer les marges de page et créer une barre de nouvelles en word?
云原生社区 大佬博客
Fs4100 lithium battery charging management IC input 12V to 8.4v charging IC
【legendre】多项式
Problem with makefile: unable to detect file updates
The national advanced computing industry innovation (Yichang) center was officially launched and jointly operated by Zhongke Shuguang and Shengzhe technologies
mixin--混入
C language floating point number storage form
搭建一个BPMN建模的Web服务
Zabbix_ Monitoring ssh/crond Service - wechat alarm
Microsoft Word 教程「5」,如何在 Word 中更改頁邊距、創建新聞稿欄?
localhost和127.0.0.1的区别?
vulnhub-The Planets: Earth
[technical fragment] implementation of renaming and filtering duplicate name files with suffixes
Canvas advanced functions (Part 1)
「Bug」问题分析 RuntimeError:which is output 0 of ReluBackward0