0%

FlipViewer Xpress在线文档转pdf

准备工作

python环境(已安装requests)

步骤

获取源地址

首先F12-Network,然后刷新一下页面。获取到当前文档页面的源地址,类似于
http://ebooks.crup.com.cn/t/xxxxx_output/web/xxxxx_opf_files/xxxxxxxxxxxxxxxxxxxx_1.swf
下划线后的数字对应页码。

安装程序包

需要安装requests用于请求文件,安装pillow用于合并pdf:

1
pip install requests pillow

python脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'''
@Author: Xhy
@Fix: kelffon wang
@Description: SWF2PDF
@LastEditTime: 2020-04-16 23:51:36
'''
from PIL import Image
import os
import sys
import requests

# By Xhy
urlStart = "http://ebooks.crup.com.cn/t/xxxxx_output/web/xxxxx_opf_files/xxxxxxxxxxxxxxxxxxxx_"
startPage = 1
endPage = 361
minDepartPage = 120
departPage = 60

def getPic(i):
url = urlStart + str(i) + ".swf"
res = requests.get(url)
if(res.status_code == 200):
with open(str(i)+'.swf', 'wb') as file:
file.write(res.content)
print(i, "Swf Saved")
else:
print(res.status_code, "Failed")
sys.exit()


def mergePng2Pdf(s, e):
imgs = []
first_img = Image.open(str(s)+".png").convert('RGB')
for i in range(s+1, e):
imgs.append(Image.open(str(i)+".png").convert('RGB'))
first_img.save('book_'+str(s)+'.pdf', 'PDF', resolution=100.0,
save_all=True, append_images=imgs)
print("PDF Saved.",'location: book_'+str(s)+'.pdf')


def do_download():
for i in range(startPage, endPage+1):
if(not os.access(str(i)+".png", os.F_OK) and not os.access(str(i)+".swf", os.F_OK)):
getPic(i)


def do_convert():
for i in range(startPage, endPage+1):
if(os.access(str(i)+".swf", os.F_OK) and not os.access(str(i)+".png", os.F_OK)):
execstr = "swfrender.exe " + \
str(i)+".swf -X 3200 -Y 4800 -o "+str(i)+".png"
val = os.system(execstr)
if(val == 0):
print(i, "Png Saved.")


def do_merge():
if (endPage-startPage) < minDepartPage:
mergePng2Pdf(startPage, endPage)
else:
depart = int((endPage-startPage)/departPage)+1
for i in range(depart):
s = startPage+i*departPage
t = s+departPage
pdfname = 'book_'+str(s)+'.pdf'
if(not os.access(pdfname, os.F_OK)):
print("PDF", i+1, "building...")
if(s > endPage):
s = endPage
if(t > endPage):
t = endPage
mergePng2Pdf(s, t)
else:
print("PDF", i+1, "existed!")

do_download()
do_convert()
do_merge()

使用时需替换开头的三个参数为具体值(默认配置为超过120页启动自动分页功能,每60页保存为1个pdf文件)
执行此脚本即可完成 下载-转换-合并pdf 操作

打包程序下载地址(包含脚本及swfrender.exe)

https://pan.baidu.com/s/13YWWebNCQU2DzuPibCnKUg 提取码: 2333
解压后,根据具体情况修改脚本,执行download.bat即可(需要先安装requests和pillow)

PS:多个pdf合并可以使用uPDF
uPDF下载地址:
蓝奏云 密码:gnsr (仅含非ocr版)