当前位置: 首页 > news >正文

精品国内网站建设成都网站排名公司

精品国内网站建设,成都网站排名公司,网站的反链要怎么做,做网站建设一年能赚多少引言 在数字化办公和学习中,PDF文件因其便携性和格式稳定性而广受欢迎。然而,处理大型PDF文件时,我们经常需要将其拆分成单独的页面,以便于管理和分享。本文将探讨如何使用Python编程语言和一些流行的库来实现PDF文件的分页处理。…

引言

在数字化办公和学习中,PDF文件因其便携性和格式稳定性而广受欢迎。然而,处理大型PDF文件时,我们经常需要将其拆分成单独的页面,以便于管理和分享。本文将探讨如何使用Python编程语言和一些流行的库来实现PDF文件的分页处理。

PDF分页的技术背景

PDF(Portable Document Format,便携式文档格式)是一种由Adobe系统公司开发的文件格式,用于表示文档的布局、文本、图形和其他元素。PDF文件广泛用于电子文档交换,因为它们可以在不同的操作系统和设备上保持一致的显示效果。

使用Python进行PDF分页

Python是一种灵活且功能强大的编程语言,拥有丰富的库支持,非常适合进行PDF文件的处理。以下是一些用于处理PDF的流行Python库:

PyPDF2

PyPDF2是一个强大的库,可以用于读取PDF文件、拆分页面、合并页面等。但是,从版本3.0.0开始,PyPDF2不再维护,推荐使用PdfReader替代PdfFileReader。

fitz (PyMuPDF)

fitz是另一个流行的库,它是MuPDF的Python绑定,提供了丰富的PDF处理功能。使用fitz,我们可以轻松地打开、解析和修改PDF文件。

实战:使用Python分页PDF

PDF上下分页

import os
import pandas as pd
from PyPDF2 import PdfFileReader, PdfFileWriterdef split_pdf(infile):split_pdf_file = []split_pdf_file_name = []if '/' in infile:in_File = infile.split('/')[2][:-4]else:in_File = infile[:-4]new_filepath = os.path.join('%s/%s') % ('./resluts', in_File)if not os.path.exists(new_filepath):os.makedirs(new_filepath)with open(infile, 'rb') as infile:reader = PdfFileReader(infile, strict=False)number_of_pages = reader.getNumPages()print("共{}页".format(number_of_pages))for i in range(number_of_pages):writer = PdfFileWriter()writer.addPage(reader.getPage(i))out_new_file = new_filepath + '/' + str(i + 1)if not os.path.exists(out_new_file):os.makedirs(out_new_file)out_file_name = out_new_file + '/' + str(i + 1) + '.pdf'with open(out_file_name, 'wb') as outfile:writer.write(outfile)split_pdf_file.append(out_file_name)split_pdf_file_name.append(out_new_file)return split_pdf_file, split_pdf_file_name

结果如下:
在这里插入图片描述

PDF左右分页


import pdfplumber
from PyPDF2 import PdfFileReader, PdfFileWriter
import os
def split_pdf(infile, out_path):if not os.path.exists(out_path):os.makedirs(out_path)with open(infile, 'rb') as infile:reader = PdfFileReader(infile)number_of_pages = reader.getNumPages()print("共{}页".format(number_of_pages))for i in range(number_of_pages):writer = PdfFileWriter()writer.addPage(reader.getPage(i))out_file_name = out_path + str(i + 1) + '.pdf'with open(out_file_name, 'wb', ) as outfile:writer.write(outfile)def PdfSplitpath(new_filepath):isExists = os.path.exists(new_filepath)if not isExists:os.makedirs(new_filepath)print("----------目录创建成功--------")else:print("---------目录已经存在----------")def SplitPDFLeft(inpath, outpath):inpath_new = os.listdir(inpath)for j in inpath_new:inpath1 = inpath + jwith open(inpath1, "rb") as in_f:input1 = PdfFileReader(in_f)output = PdfFileWriter()numPages = input1.getNumPages()for i in range(numPages):page = input1.getPage(i)page.cropBox.lowerLeft = (10, 45) page.cropBox.upperRight = (600, 841.89)output.addPage(page)with open(('%s/%s.pdf' % (outpath, j[:len(j) - 4] + '_lift')), "wb") as out_f:print("已写入第{}个pdf_lift".format(j[:len(j) - 4]))output.write(out_f)def SplitPDFRight(inpath, outpath):inpath_new = os.listdir(inpath)for j in inpath_new:inpath1 = inpath + jwith open(inpath1, "rb") as in_f:input1 = PdfFileReader(in_f)output = PdfFileWriter()numPages = input1.getNumPages()for i in range(numPages):page = input1.getPage(i)page.height = (791.89)page.width = (562.2)page.cropBox.upperRight = (600, 841.89) page.cropBox.lowerLeft = (1162.2, 50) output.addPage(page)with open(('%s/%s.pdf' % (outpath, j[:len(j) - 4] + '_right')), "wb") as out_f:print("已写入第{}个pdf_right".format(j[:len(j) - 4]))output.write(out_f)if __name__ == '__main__':in_File = './data/越南协会组织与NGO组织目录.pdf'out_Path = './data/单页/'  # 生成输出文件夹split_pdf(in_File, out_Path)new_filepath = './data/分页'PdfSplitpath(new_filepath)inpath_new = os.listdir(out_Path)print(inpath_new)print(out_Path + inpath_new[3])print((inpath_new[3])[:len(inpath_new[3]) - 4])SplitPDFRight(out_Path, new_filepath)SplitPDFLeft(out_Path, new_filepath)

结果如下

单页PDF

在这里插入图片描述

左单页PDF

在这里插入图片描述

右单页PDF

在这里插入图片描述

http://www.yayakq.cn/news/181259/

相关文章:

  • 网站策划做营销推广wordpress网站变慢
  • 网站备案率定义win主机伪静态规则 wordpress
  • 淘宝怎么才能发布网站建设广告设计公司哪家好
  • 怎么寻找要建设网站的客户群自媒体123网站
  • 东莞企业营销型网站建设wordpress调用同分类最新文章
  • 网站开发的项目需求官方网站的英文
  • 找人做网站 源码被盗用网站开发培训班 上地
  • 贵州网站建设哪家好免费小程序开发报价
  • 深圳莲花大厦住房和建设局网站彩票网站做一级代理犯法吗
  • 腾讯云做视频网站吗天猫开店流程及费用2023
  • 海南门户网站开发公司网页设计的主题分析
  • 网站建设使用哪种语言好原创网站模版
  • 网站升级 html做网站时最新菜品的背景图
  • 如何找网站开发人员石家庄百度搜索优化
  • cname解析对网站影响网络营销的实现方式有哪些
  • wordpress登录页面图标修改一个公司多个网站做优化
  • 淘客网站备案wordpress维护页面插件
  • 微信彩票网站网站建设软文代写
  • 祝贺网站改版遵义网站建设培训
  • 有专门教做蛋糕的网站建设公司网站的申请
  • 触屏手机网站wordpress建立移动m站
  • 松江网站建设哪家好宁波市铁路建设指挥部网站
  • 网上买保险网站个人博客怎么注册
  • 怎么查看网站域名怎么做网站公众号
  • php 信息分类网站开发怎么制作表格教程
  • 网站建设的报告分析网站的规划与建设 按时间顺序
  • 触屏版网站源码做外贸都得有网站吗
  • 建设一个类似淘宝的网站怎么用cms做网站
  • 天津智能网站建设找哪家谷歌广告平台
  • 国内简约网站怎么做网页个人简介