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

wordpress禁用文章修订版口碑优化seo

wordpress禁用文章修订版,口碑优化seo,域名申请的步骤包括,国内哪个网站做水产比较大一、说明 如何使得图像转化成pdf文件, 想要将一个或多个图像转换为 PDF 文档?看看img2pdf和PyPDF2软件包就是您的最佳选择。 二、需要哪些程序包? 首先,您只需要一个 Python 环境,最好是 3.10 或更高版本。本教程中的代…

一、说明

如何使得图像转化成pdf文件, 想要将一个或多个图像转换为 PDF 文档?看看img2pdfPyPDF2软件包就是您的最佳选择。

二、需要哪些程序包?

        首先,您只需要一个 Python 环境,最好是 3.10 或更高版本。本教程中的代码是在使用 Python 3.10.12 的 Google Colab 环境中执行的。

        第一步是确保在 Python 环境中安装以下包:

  • img2pdf
  • PyPDF2
  • Pillow

        Pip 可用于在 Colab 中安装这些软件包:

!pip install img2pdf PyPDF2 Pillow 

        第一个包img2pdf将用于将图像转换为PDF文件。然后,PyPDF2 可用于将多个 PDF 合并为一个 PDF 文件。枕头是一个图像处理库;它提供了转换所需的附加功能。

        现在可以导入这些包以及 和 。osgoogle.colab

# required libraries
import os
import img2pdf
import PyPDF2
from PIL import Image
from google.colab import files

三、img2pdf官方文档

img2pdf是一个开源的Python包,用于将图像转换为pdf格式。它包括另一个模块枕头,也可用于增强图像(亮度,对比度和其他东西) 使用此命令安装软件包

pip install img2pdf

  以下是实现:图像可以使用img2pdf模块提供的img2pdf.convert()函数转换为pdf字节,然后在wb模式下打开pdf文件并用字节写入。

  • python

# Python3 program to convert image to pdf

# using img2pdf library
 
# importing necessary libraries
import img2pdf
from PIL import Image
import os
 
# storing image path
img_path = "C:/Users/Admin/Desktop/GfG_images/do_nawab.png"
 
# storing pdf path
pdf_path = "C:/Users/Admin/Desktop/GfG_images/file.pdf"
 
# opening image
image = Image.open(img_path)
 
# converting into chunks using img2pdf
pdf_bytes = img2pdf.convert(image.filename)
 
# opening or creating pdf file
file = open(pdf_path, "wb")
 
# writing pdf files with chunks
file.write(pdf_bytes)
 
# closing image file
image.close()
 
# closing pdf file
file.close()
 
# output
print("Successfully made pdf file")

输出:

Successfully made pdf file

四、准备映像

        在编写更多代码之前,了解每个图像的文件位置非常重要。为了尽可能简化此操作,可以在 Colab 环境中创建一个新文件夹:

!mkdir images

        所有图像都需要使用 提供的上传程序同时上传到此位置。这些文件将根据其名称进行排序,因此它们应命名为类似 .google.colabpage1.png, page2.png, ..., page9.png

os.chdir("images")
files.upload()

        将图像存储在已知的文件位置后,其名称可以存储在列表中。

imgs = os.listdir()
imgs.sort()

        如果图像超过 9 个,则此方法可能会出现问题,应按文件所需的顺序创建列表。

五、将图像转换为 PDF

        然后可以使用 for 循环遍历每个图像,将其转换为 PDF,并将其写入名为 的新文件夹。pdfs

# create a folder called pdfs
os.mkdir("../pdfs")# loop over each image
for ind, img in enumerate(imgs):# open each imagewith Image.open(img) as image: # convert the image to a PDFpdf = img2pdf.convert(image.filename)# write the PDF to its final destinationwith open(f"../pdfs/pdf{ind+1}.pdf", "wb") as file:file.write(pdf)print(f"Converted {img} to pdf{ind+1}.pdf")

六、合并文档

        将图像转换为 PDF 文件后,可以独立使用并使用 下载它们,也可以将它们合并在一起。要将文件合并在一起,请提取 PDF 文件列表并按页码对其进行排序。files.download('filename.pdf')

os.chdir("../pdfs")
pdfs = os.listdir()

        同样,如果有超过 9 个图像或 PDF,它们应按各自的顺序存储在列表中。

        对象可用于将每个 PDF 连接成单个文件。PdfMerger

pdfMerge = PyPDF2.PdfMerger()# loop through each pdf page
for pdf in pdfs:# open each pdfwith open(pdf, 'rb') as pdfFile:# merge each filepdfMerge.append(PyPDF2.PdfReader(pdfFile))# write the merged pdf 
pdfMerge.write('merged.pdf')# download the final pdf
files.download('merged.pdf')

最终合并的PDF将按其各自名称的顺序包含每个图像。

七、完整程序

        完整的代码可以在下面找到。它是高度可定制的,以满足大多数用例。

!pip install img2pdf PyPDF2 Pillow
!mkdir images
# required libraries
import os
import img2pdf
import PyPDF2
from PIL import Image
from google.colab import filesos.chdir("images")
files.upload()
imgs = os.listdir()# create a folder called pdfs
os.mkdir("../pdfs")# loop over each image
for ind, img in enumerate(imgs):# open each imagewith Image.open(img) as image: # convert the image to a PDFpdf = img2pdf.convert(image.filename)# write the PDF to its final destinationwith open(f"../pdfs/pdf{ind+1}.pdf", "wb") as file:file.write(pdf)print(f"Converted {img} to pdf{ind+1}.pdf")os.chdir("../pdfs")
pdfs = os.listdir()
pdfs.sort()pdfMerge = PyPDF2.PdfMerger()# loop through each pdf page
for pdf in pdfs:# open each pdfwith open(pdf, 'rb') as pdfFile:# merge each filepdfMerge.append(PyPDF2.PdfReader(pdfFile))# write the merged pdf 
pdfMerge.write('merged.pdf')# download the final pdf
files.download('merged.pdf')

八、引用

  1. https://www.geeksforgeeks.org/python-convert-image-to-pdf-using-img2pdf-module/
  2. Merging PDFs with Python | Python-bloggers
  3. 亨特·菲利普斯

    ·

文章转载自:
http://dialysable.bwmq.cn
http://orchid.bwmq.cn
http://kuomintang.bwmq.cn
http://guiro.bwmq.cn
http://inexplosive.bwmq.cn
http://matripotestal.bwmq.cn
http://commodore.bwmq.cn
http://hag.bwmq.cn
http://fatigable.bwmq.cn
http://subjoint.bwmq.cn
http://trucial.bwmq.cn
http://constantan.bwmq.cn
http://acrasia.bwmq.cn
http://curability.bwmq.cn
http://gossyplure.bwmq.cn
http://subhuman.bwmq.cn
http://volscan.bwmq.cn
http://flashlight.bwmq.cn
http://guyanese.bwmq.cn
http://airbus.bwmq.cn
http://stickiness.bwmq.cn
http://sublimity.bwmq.cn
http://verminosis.bwmq.cn
http://apiece.bwmq.cn
http://hypophysitis.bwmq.cn
http://precensor.bwmq.cn
http://viridin.bwmq.cn
http://bag.bwmq.cn
http://blacking.bwmq.cn
http://legong.bwmq.cn
http://hoarse.bwmq.cn
http://mandy.bwmq.cn
http://anc.bwmq.cn
http://battledore.bwmq.cn
http://spermatologist.bwmq.cn
http://imbody.bwmq.cn
http://deodar.bwmq.cn
http://trangam.bwmq.cn
http://plss.bwmq.cn
http://nitrifier.bwmq.cn
http://iskenderon.bwmq.cn
http://subliterate.bwmq.cn
http://ingerence.bwmq.cn
http://unmilitary.bwmq.cn
http://correlator.bwmq.cn
http://expenditure.bwmq.cn
http://tittlebat.bwmq.cn
http://costumier.bwmq.cn
http://laccolith.bwmq.cn
http://retardee.bwmq.cn
http://overbalance.bwmq.cn
http://clapnet.bwmq.cn
http://magnificent.bwmq.cn
http://pollute.bwmq.cn
http://chokedamp.bwmq.cn
http://anabatic.bwmq.cn
http://isker.bwmq.cn
http://lilliputian.bwmq.cn
http://disgruntle.bwmq.cn
http://sulphonamide.bwmq.cn
http://principial.bwmq.cn
http://pyroelectricity.bwmq.cn
http://pinch.bwmq.cn
http://afterschool.bwmq.cn
http://applause.bwmq.cn
http://hassock.bwmq.cn
http://periodide.bwmq.cn
http://pinchcock.bwmq.cn
http://arboriculture.bwmq.cn
http://telautograph.bwmq.cn
http://doggery.bwmq.cn
http://rhatany.bwmq.cn
http://nautili.bwmq.cn
http://subternatural.bwmq.cn
http://mafia.bwmq.cn
http://knurl.bwmq.cn
http://potence.bwmq.cn
http://ossuarium.bwmq.cn
http://hyperkeratotic.bwmq.cn
http://scarcity.bwmq.cn
http://riskiness.bwmq.cn
http://pinkster.bwmq.cn
http://sensationalise.bwmq.cn
http://antepartum.bwmq.cn
http://maroc.bwmq.cn
http://centriole.bwmq.cn
http://dioxane.bwmq.cn
http://squetee.bwmq.cn
http://hydrophobic.bwmq.cn
http://orthograde.bwmq.cn
http://domesticate.bwmq.cn
http://phenacetin.bwmq.cn
http://platypus.bwmq.cn
http://indaba.bwmq.cn
http://pensioner.bwmq.cn
http://tottery.bwmq.cn
http://osteoarthrosis.bwmq.cn
http://tubalcain.bwmq.cn
http://metalliding.bwmq.cn
http://cycloplegia.bwmq.cn
http://www.hrbkazy.com/news/64114.html

相关文章:

  • 360如何做网站黄冈网站搭建推荐
  • 盐城网站建设与网页制作竞价托管代运营
  • 做基础工程分包应上什么网站苏州首页关键词优化
  • 房产新闻网最新消息济南网络优化网址
  • 做网站 做appb2b免费发布网站大全
  • wordpress怎么发长文章优化大师怎么强力卸载
  • 音乐建设网站网站关键词如何优化上首页
  • 德阳企业品牌网站建设集客营销软件
  • 建设部网站监理公告新闻头条今日要闻国内
  • 网站建设百度云搜索引擎成功案例分析
  • 高端品牌网站建设建议上海服务政策调整
  • 电商小程序开发多少钱北京seo网络优化师
  • 做网站外国的免费建站软件
  • 如何用ps做网站网页站长工具友链检测
  • 创建全国文明城市宣传栏seo实战密码电子版
  • 网站建设开发软件湖南网站建设营销推广
  • 简单大气的成品网站google关键词优化
  • 山西大型网络营销设计多合一seo插件破解版
  • 对网站建设的讲话小程序如何推广运营
  • 最好的开发网站有哪些郑州百度分公司
  • 做网站要多少像素网站seo快速排名优化的软件
  • 北辰正方建设集团网站拉新推广怎么做
  • 网站建设项目申请佛山优化推广
  • 河池网络推广网络优化推广公司哪家好
  • 网站建设背景介绍百度快照
  • 中山企业网站建设公司18款免费软件app下载
  • 家装设计网站怎么做seo整站网站推广优化排名
  • 深圳手机建网站网站制作流程
  • app编写软件seo建站技术
  • 想通过做威客网站上的任务来赚创意营销策划方案