|
楼主 |
发表于 2024-2-29 09:06
|
显示全部楼层
- from PyPDF2 import PdfReader, PdfWriter, PdfReader
- reader=PdfReader("instance.pdf",strict=False)
- writer=PdfWriter()
- for i in range(len(reader.pages)):
- writer.add_page(reader.pages[0])
- ##添加注释
- writer.add_metadata(
- {
- "/Auther":"PythonABC",
- "/Producer":'pythonabc.org',
- "/subjiect":"追星演技派",
- "Creator":"2022",
- "keywords":"演技 颜值 亲和力"
- }
- ) ###add_metadata的参数是字典类型
- #将写对象的内容保存成PDF文件
- with open('metaActor.pdf',"wb") as f:
- writer.write(f)
- reader=PdfReader('metaActor.pdf')
- print("页数:",len(reader.pages))
- # info=reader.getDocumentInfo()
- info=reader.metadata
- # info=reader.
- # info=reader.pages[1]
- # print(info.author)
复制代码 |
|