python自动翻译pdf_在Python中自动执行PDF

python自动翻译pdf

Modules used:

使用的模块:

In this script, we will use PyPDF2 module which will provide us various functions such as to extract the data and read the pdf file and split the file and write a new file.

在此脚本中,我们将使用PyPDF2模块,该模块将为我们提供各种功能,例如提取数据,读取pdf文件,拆分文件并写入新文件。

Download PyPDF2:

下载PyPDF2:

  • General Way: pip install PyPDF2

    通用方式:pip安装PyPDF2

  • Pycharm Users: Go to the python project interpreter and install it from there.

    Pycharm用户:转到python项目解释器并从那里安装它。

Various function provided by PyPDF2:

PyPDF2提供的各种功能:

  1. PyPDF2.PdfFileReader(): This function will read our pdf and return us a data value that we will store in a variable (Let's take as Pdf_Data).

    PyPDF2.PdfFileReader() :此函数将读取我们的pdf并返回一个将存储在变量中的数据值(以Pdf_Data为例)。

  2. Pdf_Data.isEncrypted: This Function will help us to check if the pdf file is Encrypted.

    Pdf_Data.isEncrypted :此功能将帮助我们检查pdf文件是否已加密。

  3. Pdf_Data.decrypt("<password>"): This function will help us to decrypt the pdf file and inside this function, we have to put the password and our pdf file will get decrypted.

    Pdf_Data.decrypt(“ <password>”) :此函数将帮助我们解密pdf文件,并且在此函数内部,我们必须输入密码,然后pdf文件将被解密。

  4. Pdf_Data.numPages: This Function will return us the number of pages our pdf contain.

    Pdf_Data.numPages :此函数将向我们返回pdf包含的页面数。

  5. Pdf_Data.getPage(0): This function will return us the data on the first page, here 0 seems to be the first page and 1 to be the second page, the things will go like indexing in python.

    Pdf_Data.getPage(0) :此函数将返回第一页上的数据,这里0似乎是第一页,而1则是第二页,事情就像在python中建立索引一样。

  6. Pdf_Writer=PyPDF2.PdfFileWriter(): This function will create a variable that will help us to create a new pdf file.

    Pdf_Writer = PyPDF2.PdfFileWriter() :此函数将创建一个变量,该变量将帮助我们创建新的pdf文件。

  7. Pdf_Writer.addPage(<The Page Data>): This function will add the pdf page to the newly created pdf file.

    Pdf_Writer.addPage(<页面数据>) :此函数会将pdf页面添加到新创建的pdf文件中。

Note: The text Extraction can be done only with the pdf files which have text.

注意:只有具有text的pdf文件才能进行文本提取

Python代码读取文件并提取文本 (Python code to read the file and extract the text)

# import the modules
import PyPDF2
# open the file and read the content
# open the file
Pdf_Open=open("/home/abhinav/Downloads/CS_Defination-converted.pdf","rb")
# read the file and store the content
Pdf_Data=PyPDF2.PdfFileReader(Pdf_Open)
# get the number of pages
print(Pdf_Data.numPages)
# Lets extract the data for the first page
# we will use getPage command to get the page
# using 0 for 1st page
First_page=Pdf_Data.getPage(0)
# printing the text
print(First_page.extractText())

Output:

输出:

Automating pdfs in Python

This is the extracted text from the pdf that we have given in input. In this way, we can extract the text from the pdf.

这是我们在输入中从pdf中提取的文本。 这样,我们可以从pdf中提取文本。

Now we will create a pdf file and we will add the starting and the last page of the above-used pdf in that file.

现在我们将创建一个pdf文件 ,并将上面使用的pdf的开始和最后一页添加到该文件中。

Let's see the code,

让我们看一下代码,

# import the modules
import PyPDF2
# open the file and read the content
# open the file
Pdf_Open=open("/home/abhinav/Downloads/Abhinav_Gangrade.pdf","rb")
# read the file and store the content
Pdf_Data=PyPDF2.PdfFileReader(Pdf_Open)
# get the number of pages
print(Pdf_Data.numPages)
# Create a pdf writer
pdf_writer=PyPDF2.PdfFileWriter()
# we will take the first page of the above pdf
first_page=Pdf_Data.getPage(0)
# we will take the last page of the above pdf
# as the last page will be Total number of pages-1
last_page=Pdf_Data.getPage((Pdf_Data.numPages)-1)
# adding page to the new pdf
pdf_writer.addPage(first_page)
pdf_writer.addPage(last_page)
# create a blank file
New_pdf=open("/home/abhinav/Downloads/Hello.pdf","wb")
# add the content to the blank file
pdf_writer.write(New_pdf)
# Now close the file

From the above code, we can create a new pdf with the help of an existing pdf, and after that, we have taken the first and last page of the existing pdf and combine them and wrote it in the new pdf. In that way, we can create a pdf with the help of existing pdfs.

从上面的代码中,我们可以在现有pdf的帮助下创建一个新pdf,然后,我们将现有pdf的第一页和最后一页进行合并,并将它们写入新pdf中。 这样,我们可以在现有pdf的帮助下创建pdf。

翻译自: https://www.includehelp.com/python/automating-pdfs.aspx

python自动翻译pdf

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380688.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

设置DVWA出现Could not connect to the MySQL service. Please check the config的解决方法,默认登录账号

按照这个路径&#xff0c;找到config.inc.php文件&#xff0c;打开 找到下面三个语句 db_server:一般填127.0.0.1&#xff0c;如果修改了mysql的端口号&#xff0c;要在后面加上修改后的端口号&#xff0c;默认为3306 db_user:自己mysql数据库的用户名 db_password&#xff1…

java解析excel的js页面,Java导入Excel文件页面实现JS

Excel导入&#xff1a;页面创建导入按钮&#xff0c;如&#xff1a;代码&#xff1a;导入交易JS&#xff1a;function upload(){layer.open({type : 2, //层类型title :导入文件, //标题shadeClose : true,//是否点击遮罩关闭shade : [ 0.4, #000 ], //遮罩maxmin : false, //开…

详谈asp生成静态页方法

生成静态页的好处不用说&#xff0c;当今大型网站&#xff0c;为缓解服务器端的压力许的的页面都改用了静态的页面&#xff0c;并利用AJAX技术动态地更新其中的部分内容&#xff0c;如广告等。一个简单的不用模板可以直接生成HTML静态页的方法. 如一个正常的index.asp动态页面&…

模糊逻辑系统_在模糊逻辑系统中工作 人工智能

模糊逻辑系统As discussed earlier, the Fuzzy Logic System consists of 4 components: the Knowledge Base, Fuzzification Module, Inference Engine, and the Defuzzification Module. We know how the data and information flow between these components, but we do not…

关于用户角色权限的一点想法(1) 选择自 biggie 的 Blog

原文&#xff08;http://dev.csdn.net/article/19/19751.shtm&#xff09; 前言&#xff1a;权限往往是一个极其复杂的问题&#xff0c;但也可简单表述为这样的逻辑表达式&#xff1a;判断“Who对What(Which)进行How的操作”的逻辑表达式是否为真。针对不同的应用&#xff0c;需…

使用anconada 的conda更换环境

打开命令行界面。cmd&#xff0c;直接打开 查看有些环境 conda env list 我这里有两个环境使用指定的环境 我这里就用py27 命令&#xff1a;activate环境名 py27在前面&#xff0c;已经成功更换了退出使用某个环境 conda deactivate 前面已经没有py27&#xff0c;表示已经退…

php采集分页数据,如何通过php+wordpress实现分页获取数据

1.首先我们通过WordPress来搭建我们的博客网站&#xff0c;需要实现分页获取数据&#xff0c;我们需要了解一下WordPress给我们提供的api。主要是get_posts()这个api的使用方法。函数的结构大概长这么个样子&#xff1a;<?php get_posts($args); ?> &#xff0c;其中…

离散结构和离散数学中文书_在离散数学中对场景执行的操作

离散结构和离散数学中文书Prerequisite: Set theory and types of set in Discrete Mathematics 先决条件&#xff1a; 离散数学中的集合论和集合类型 集的基数 (Cardinality of set) It is the number of elements in a set denoted like, A {1, 2, 3, 4} 它是集合中元素的数…

家纺B2C优雅100获IDG及DCM 1000万美元投资

网易科技讯 3月3日下午动静&#xff0c;家纺网上商城优雅100(uya100.com) 首创人陈腾华往日吐露&#xff0c;该公司明天不日完成了1000万美元的首轮融资&#xff0c;投资方为IDG及DCM。陈腾华以有合同约定为由拒绝流露更详细的财务细节。陈腾华说&#xff0c;这1000万美元曾经到…

看看DIV+CSS都能做那些事情!

一个很经典的网站,学习ING. http://www.csszengarden.com/转载于:https://www.cnblogs.com/lbk/archive/2005/03/30/128401.html

手动打开和关闭windows的相关服务

winR&#xff0c;输入services.msc 找到指定的服务打开或者关闭

路由表,路由,路由规则_路由和路由表简介

路由表,路由,路由规则路由介绍 (Introduction to Routing ) The process of sending packets from one network to another is called routing. Routing is of two types of static and dynamic. Routes are based on the destination network. Routing is to find the best pa…

PetShop之ASP.NET缓存(转载)

《解剖PetShop》系列之四 四 PetShop之ASP.NET缓存 如果对微型计算机硬件系统有足够的了解&#xff0c;那么我们对于Cache这个名词一定是耳熟能详的。在CPU以及主板的芯片中&#xff0c;都引入了这种名为高速缓冲存 储器&#xff08;Cache&#xff09;的技术。因为Cache的存取速…

php代码审计步骤,php代码审计(一)-----调试函数

本篇文章给大家分享的内容是调试函数&#xff0c;有兴趣的朋友可以看一下&#xff0c;也可以给有需要帮助的同学一点参考两种最基本的输出方法echo和print/***echo 是一个语言结构&#xff0c;有无括号均可使用&#xff1a;echo 或 echo()*///打印字符串echo "hello"…

XML+Application来编写计数器(一)

1)网站总共访问人数计数器 这种计数器我们可以使用XML来实现&#xff0c;打开windows的记事本在其中录入以下数据另存为count.xml。 <MyCount> <AllCount>0</AllCount> <MaxCount>0</MaxCount> </MyCount> 其中AllCount标签是记录web页面访…

使用python学线性代数_最简单的神经网络简介| 使用Python的线性代数

使用python学线性代数A neural network is a powerful tool often utilized in Machine Learning because neural networks are fundamentally very mathematical. We will use our basics of Linear Algebra and NumPy to understand the foundation of Machine Learning usin…

php七天登录,十天学会php之第七天

十天学会php之第七天推荐查看本文HTML版本学习目的&#xff1a;学会SESSION的使用SESSION的作用很多&#xff0c;最多用的就是站点内页面间变量传递。在页面开始我们要session_start();开启SESSION&#xff1b;然后就可以使用SESSION变量了&#xff0c;比如说要赋值就是…

电脑安装了mysql,但找不到mysql服务

首先找到mysql的bin文件目录&#xff0c;我的是在&#xff1a;C:\Program Files\mysql-5.7.27-winx64\bin 然后找到下图内容&#xff0c;右键以管理者身份运行 然后cd 到mysql的bin目录 在输入mysqld -install 服务就重启好了

Item 34. Restricting Heap Allocation

Item 34. Restricting Heap Allocation1、什么情况下要限制堆分配&#xff1f;假如一个句柄对象&#xff08;"handle" object &#xff09;维护了一个体对象&#xff08;"body" object&#xff09;的引用数量&#xff0c;就需要确保对象的析构函数调用。局…

Web Service 缓存

由于微软的Web service实现是基于Asp.net,所以会出现缓存也就在情理之中了.主要有2中缓存:输出缓存和数据缓存.由于Web Service的缓存管理与asp.net基本是一样的,就不说他的原理,主要说一下在Web service中是如何实现的. 输出缓存 实现方法是在WebMethod这个特性里面加一个属性…