使用Python确定PDF是否由Google文档生成

问题描述 投票:-1回答:1

我想使用Python判断PDF是否由Google文档创建。我可以通过PyPDF2收集某种元数据来确定这一点吗?

python pdf google-docs pypdf2
1个回答
0
投票

对由Google文档创建的文档进行pdf.getDocumentInfo()时,它返回{'/Producer': u'Skia/PDF m83'}。我在一些Google文档上对此进行了测试,并且看来已经签出了。这很有意义-Skia是Google project,因此必须使用它们在后端上生成文档。

所以您可以简单地做:

import PyPDF2
GOOGLE_DOCS_PDF_METADATA = {'/Producer': u'Skia/PDF m83'}

def file_is_google_doc(pdf_file_path) 
    pdf = PyPDF2.PdfFileReader(pdf_file_path)
    return pdf.getDocumentInfo() == GOOGLE_DOCS_PDF_METADATA
© www.soinside.com 2019 - 2024. All rights reserved.