Code Monkey home page Code Monkey logo

Comments (2)

will-afs avatar will-afs commented on August 26, 2024
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
import urllib.request
from io import BytesIO

def extract_pdf_metadata(pdf_file:str) -> dict:
    """Returns the metadata of a PDF

    Parameters:
    pdf_path (str) : the path of the PDF file of which metadata should be extracted

    Returns:
    dict: metadata of the PDF, presented as a JSON structured as follows : 
        {
            metadata:{
                        "Author": "AURORE",
                        "CreationDate": "D:20200325185329+01'00'",
                        "Creator": "Microsoft Office Word 2007",
                        "ModDate": "D:20210311153835+01'00'",
                        "Producer": "Microsoft Office Word 2007",
                        "Title": "DOSSIER COUP DE POUCE 2020"
                    }
            content:"Lorem ipsum dolor sit amet, ..."
        }
    """
    pdf_parser = PDFParser(pdf_file)
    doc = PDFDocument(pdf_parser)
    metadata = doc.info[0]
    for (key, value) in doc.info[0].items():
        # Need to decode each value from bytestrings toward strings
        metadata[key] = value.decode("utf-8", errors='ignore')
    return metadata
        

if __name__ == '__main__':
    response = urllib.request.urlopen('http://arxiv.org/pdf/cs/9308101v1')
    pdf_txt = response.read()
    fileObj = BytesIO()
    fileObj.write(pdf_txt)
    metadata = extract_pdf_metadata(fileObj)
    print(metadata)

from pytdelivery.

will-afs avatar will-afs commented on August 26, 2024

Closed with commit #cebc9a24d06933fd9b969901ba1fd8b38ad51861

from pytdelivery.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.