栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python鍘嬬缉pdf_python鍒囧壊pdf?

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python鍘嬬缉pdf_python鍒囧壊pdf?

在阅读PDF文档时,个人习惯在笔记本上双页阅读,但有的PDF边距太宽,看起来字很小,阅读吃力

本代码用来裁剪整个PDF文档间距

import PyPDF2
import os

left_margin = right_margin = 30
top_margin = 5
bottom_margin = 5

input_file_path = []
output_file_path = []
os.makedirs('.\修改')  # 新建文件夹

file_path = '.\'
file_list = os.listdir(file_path)
for i in file_list:
    if os.path.splitext(i)[1] == '.pdf':
        input_file_path.append('.\' + i)
        output_file_path.append('.\修改\' + '修改' + i)


def split(page):
    page.mediaBox.lowerLeft = (left_margin, bottom_margin)
    page.mediaBox.lowerRight = (width - right_margin, bottom_margin)
    page.mediaBox.upperLeft = (left_margin, height - top_margin)
    page.mediaBox.upperRight = (width - right_margin, height - top_margin)


for m in range(len(input_file_path)):
    input_file = PyPDF2.PdfFileReader(open(input_file_path[m], 'rb'))
    output_file = PyPDF2.PdfFileWriter()

   page_info = input_file.getPage(0)
    width = float(page_info.mediaBox.getWidth())
    height = float(page_info.mediaBox.getHeight())
    page_count = input_file.getNumPages()

   for page_num in range(page_count):
        this_page = input_file.getPage(page_num)
        split(this_page)
        output_file.addPage(this_page)

   output_file.write(open(output_file_path[m], 'wb'))

使用之前

使用之后

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/783074.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号