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

郑州seo培训班网站优化 流量

郑州seo培训班,网站优化 流量,论坛推广的步骤,宁波百度seo点击软件一、说明 如何使得图像转化成pdf文件#xff0c; 想要将一个或多个图像转换为 PDF 文档#xff1f;看看img2pdf和PyPDF2软件包就是您的最佳选择。 二、需要哪些程序包#xff1f; 首先#xff0c;您只需要一个 Python 环境#xff0c;最好是 3.10 或更高版本。本教程中的代… 一、说明 如何使得图像转化成pdf文件 想要将一个或多个图像转换为 PDF 文档看看img2pdf和PyPDF2软件包就是您的最佳选择。 二、需要哪些程序包         首先您只需要一个 Python 环境最好是 3.10 或更高版本。本教程中的代码是在使用 Python 3.10.12 的 Google Colab 环境中执行的。         第一步是确保在 Python 环境中安装以下包 img2pdfPyPDF2Pillow         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{ind1}.pdf, wb) as file:file.write(pdf)print(fConverted {img} to pdf{ind1}.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{ind1}.pdf, wb) as file:file.write(pdf)print(fConverted {img} to pdf{ind1}.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) 八、引用 https://www.geeksforgeeks.org/python-convert-image-to-pdf-using-img2pdf-module/Merging PDFs with Python | Python-bloggers 亨特·菲利普斯 ·
http://www.hkea.cn/news/14320678/

相关文章:

  • 怎样建网站卖东西响应式网站 html
  • 旅游网站简介网站建设用什么软件
  • 上传图片的网站要怎么做上线了怎么建网站
  • 电子商务网站建设详细策划书WordPress结婚主题模板
  • 建站宝盒里的手机网站如何推广公众号文章
  • 网站后台如何更新建视频网站的费用
  • 网站建设国内现状设计很好看的网站
  • seo网站建设哪家专业wordpress 推荐
  • 网站负责人照片页面模板图片
  • 网站是公司域名是个人可以吗线上营销方式6种
  • 石家庄建设网站知雅汇网页设计实训报告
  • 网站后台显示连接已重置wordpress 增加磁盘容量
  • 常熟网站网站建设数据百度做网站好用吗
  • 苏州乡村旅游网站建设策划书做精神科网站
  • 弹幕网站怎么做wordpress视频加密
  • 河北省建设厅正规网站百度风云榜小说排行榜历届榜单
  • 自学网站建设工资事业单位网站建设的账务处理
  • 军队网站建设方案建站产品
  • 看英语做游戏的网站百度收录量
  • 直播网站建设书籍电子商务网站建设实验总结
  • 山东省城乡与住房建设厅网站首页如何在电脑上登录wordpress
  • 做外贸的网站有那些郴州旅游攻略
  • 网站建设的公司收费标准技术支持凯里网站建设
  • 唐山网站定制wordpress官方主题哪个好
  • 四川省住房和城乡建设网站自己怎么制作企业网站
  • wordpress网站导出购物商城建设网站
  • 什么网站不用备案泰安营销型网站建设
  • 网站开发的图标网站如何做导航条下拉菜单
  • 郑州那个公司做网站好影城网站建设
  • 西班牙网站后缀网站开发人员注意事项