如何使用python編寫PDF轉換器?

2021-10-19 07:49:53 字數 3823 閱讀 6976

想必小夥伴都經歷過,當你想要把pdf轉為word時,自己打字赫赫甩在你眼前:

不充錢就想白嫖?? 想得美~

然而,kimol君是不會退縮的,畢竟迎難而上是傳統美德。於是,今天的主題出來了:用python寫乙個pdf轉word的小工具(基於某**介面)。

實現**:

import time

import requests

class

pdf2word()

: def __init__

(self)

: self.machineid =

'ccc052ee5200088b92342303c4ea9399'

self.token =

'' self.guid =

'' self.keytag =

''

def producetoken

(self)

: url =

headers =

data =

res = requests.

post

(url,headers=headers,data=data)

res_json = res.

json()

if res_json[

'code']==

10000

: self.token = res_json[

'token'

] self.guid = res_json[

'guid'

]print

('成功獲取token'

)return true

else

:return false

def uploadpdf

(self,filepath)

: filename = filepath.

split

('/')[

-1] files =

url =

headers =

params =((

'tasktype'

,'pdf2word'),

('phonenumber',''

),('loginkey',''

),('machineid'

, self.machineid),(

'token'

, self.token),(

'limitsize'

,'2048'),

('pdfname'

, filename),(

'queuekey'

, self.guid),(

'uploadtime',''

),('filecount'

,'1'),

('fileindex'

,'1'),

('pagerange'

,'all'),

('picturequality',''

),('outputfileextension'

,'docx'),

('picturerotate'

,'0,undefined'),

('filesequence'

,'0,undefined'),

('filepwd',''

),('iconsize',''

),('picturetoonepdf',''

),('isshare'

,'0'),

('softname'

,'pdfonlineconverter'),

('softversion'

,'v5.0'),

('validpagescount'

,'20'),

('limituse'

,'1'),

('filespwdlist',''

),('filecountwater'

,'1'),

('languagefrom',''

),('languageto',''

),('cadverchose',''

),('pictureforecolor',''

),('picturebackcolor',''

),('id'

,'wu_file_1'),

('name'

, filename),(

'type',)

,('lastmodifieddate',''

),('size',''

),) res= requests.

post

(url,headers=headers,params=params,files=files)

res_json = res.

json()

if res_json[

'message']==

'上傳成功'

: self.keytag = res_json[

'keytag'

]print

('成功上傳pdf'

)return true

else

:return false

def progress

(self)

: url =

headers =

data =

res= requests.

post

(url,headers=headers,data=data)

res_json = res.

json()

if res_json[

'message']==

'處理成功'

:print

('pdf處理完成'

)return true

else

:print

('pdf處理中'

)return false

def downloadword

(self,output)

: url =

%self.keytag

res = requests.

get(url)

with open

(output,

'wb'

) as f:

f.write

(res.content)

print

(%output)

def convertpdf

(self,filepath,outpath)

: filename = filepath.

split

('/')[

-1] filename = filename.

split

('.')[

0]+'.docx'

self.

producetoken()

self.

uploadpdf

(filepath)

while true:

res = self.

progress()

if res == true:

break

time.

sleep(1

) self.

downloadword

(outpath+filename)``

如何使用C C 為Python編寫DLL SO

開門見山,直接闡述步驟。如果使用c語言,新建test.c檔案,並輸入以下內容 test.c declspec dllexport int sum int a,int b 如果使用c 語言,新建test.cpp檔案,並輸入以下內容 test.cpp define dllexport extern c ...

使用IDLE編寫Python

idle python gui 是乙個功能完備的 ide,允許你再這個ide中編寫 另外還有乙個python shell python的互動模式 可以在其上面進行程式設計練習 idle提供了大量的特性 1.tab鍵自動補全 先輸入前面幾個字母,然後按下tab鍵,idle會自動匹配 2.回退 語句 組...

如何使用PHP編寫daemon process

今天下午在segmentfault.com看到乙個提問,提問標題是 php怎麼做服務化 其中問道php是不是只能以web方式呼叫。其實很多人對php的使用場景都有誤解,認為php只能用於編寫web指令碼,實際上,從php4開始,php的使用場景早已不限於處理web請求。從php的架構體系來說,php...