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

您的位置:首頁技術文章
文章詳情頁

如何用python插入獨創性聲明

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

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

一、代碼分析

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

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和獨創性聲明的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))

將結果保存到本地:

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

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

二、完整代碼

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

# -*- 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)) # 保存插入后的結果output.write(open(outputName,’wb’))print(’'%s'已經成功插入到'%s'的第%d頁’%(insertName,thesisName,pos))

運行效果如下:

如何用python插入獨創性聲明

打開生成的output.pdf,可以發現已經成功插入。

寫在最后

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

以上就是如何用python插入獨創性聲明的詳細內容,更多關于用python插入獨創性聲明的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 花莲县| 景谷| 渭源县| 隆安县| 唐山市| 扶绥县| 奉贤区| 梁山县| 凌源市| 富锦市| 长沙县| 潜山县| 江陵县| 鱼台县| 安顺市| 阿坝县| 蒲城县| 晋江市| 岳池县| 宁安市| 郁南县| 宿州市| 屯昌县| 岳阳县| 邢台市| 民权县| 泸州市| 吉木萨尔县| 开江县| 合川市| 台前县| 蕲春县| 汶上县| 兴化市| 岳普湖县| 旬邑县| 噶尔县| 巴彦县| 西华县| 宁夏| 九江县|