国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

如何用python插入獨(dú)創(chuàng)性聲明

瀏覽:130日期:2022-06-23 16:36:04

想必寫畢設(shè)的時候,大家都會遇到一個問題,那就是得在明評版的論文里面插入一個獨(dú)創(chuàng)性聲明。就因為這個事情,我折騰了好久,各種在線網(wǎng)站都試過了,然而基本都需要充值或者會員啥的。(小聲嚷嚷:“萬惡的資本”)害~一不做二不休,我干脆自己寫個小工具好了。

一、代碼分析

利用PyPDF2庫便可輕松地對PDF文件進(jìn)行處理,具體用法大家可以參考這里。首先是安裝這個庫:

pip install PyPDF2

定義輸入和輸出對象:

# 定義輸出對象outputName = ’output.pdf’output = PdfFileWriter()# 定義讀取對象thesisPDF = PdfFileReader(open(thesisName,’rb’))insertPDF = PdfFileReader(open(insertName,’rb’))N_page = thesisPDF.getNumPages()pos = int(input(’論文一共有'%d'頁,請輸入需要插入的位置:’%N_page))

分別讀取論文的PDF和獨(dú)創(chuàng)性聲明的PDF,隨后將聲明插入到論文中的指定頁面:

# 將聲明插入到指定頁面for i in range(pos): output.addPage(thesisPDF.getPage(i))output.addPage(insertPDF.getPage(0)) # 插入for i in range(pos,N_page): output.addPage(thesisPDF.getPage(i))

將結(jié)果保存到本地:

# 保存插入后的結(jié)果output.write(open(outputName,’wb’))

到這里,我們就已經(jīng)成功的把聲明插入到指定的頁面中了。你沒有看錯,就是這么簡單~

二、完整代碼

將以上幾部分整合起來,完整的代碼如下:

# -*- coding: utf-8 -*-'''Created on Thu Nov 5 20:13:18 2020@author: kimol_love'''import osfrom PyPDF2 import PdfFileWriter, PdfFileReader# 用戶輸入論文名while True: thesisName = input(’請輸入論文的文件名:’) if not os.path.exists(thesisName): print(’文件不存在,請重新輸入!’) continue if thesisName[-4:].lower() != ’.pdf’: print(’后綴錯誤,請重新輸入!’) continue break# 用戶輸入需要插入的頁面while True: insertName = input(’請輸入聲明的文件名:’) if not os.path.exists(insertName): print(’文件不存在,請重新輸入!’) continue if thesisName[-4:].lower() != ’.pdf’: print(’后綴錯誤,請重新輸入!’) continue break# 定義輸出對象outputName = ’output.pdf’output = PdfFileWriter()# 定義讀取對象thesisPDF = PdfFileReader(open(thesisName,’rb’))insertPDF = PdfFileReader(open(insertName,’rb’))N_page = thesisPDF.getNumPages()pos = int(input(’論文一共有'%d'頁,請輸入需要插入的位置:’%N_page))# 將聲明插入到指定頁面for i in range(pos): output.addPage(thesisPDF.getPage(i))output.addPage(insertPDF.getPage(0)) # 插入for i in range(pos,N_page): output.addPage(thesisPDF.getPage(i)) # 保存插入后的結(jié)果output.write(open(outputName,’wb’))print(’'%s'已經(jīng)成功插入到'%s'的第%d頁’%(insertName,thesisName,pos))

運(yùn)行效果如下:

如何用python插入獨(dú)創(chuàng)性聲明

打開生成的output.pdf,可以發(fā)現(xiàn)已經(jīng)成功插入。

寫在最后

最后,感謝各位大大的耐心閱讀,咋們下次再會~

以上就是如何用python插入獨(dú)創(chuàng)性聲明的詳細(xì)內(nèi)容,更多關(guān)于用python插入獨(dú)創(chuàng)性聲明的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 南京市| 新邵县| 高州市| 昌乐县| 星子县| 疏勒县| 怀安县| 昆明市| 伊吾县| 嘉善县| 云南省| 莎车县| 泗水县| 罗源县| 新闻| 竹北市| 罗甸县| 德化县| 个旧市| 清苑县| 陵水| 龙江县| 宁陵县| 新建县| 新和县| 兰州市| 拜城县| 随州市| 贡嘎县| 陈巴尔虎旗| 亚东县| 铜川市| 柞水县| 都安| 呼玛县| 安阳县| 陆河县| 水城县| 红原县| 孝昌县| 双鸭山市|