简体   繁体   中英

Batch Export PDF Properties

TL;DR

I'm looking to take a file directory full of PDF files and "export" their properties, specifically the page number, to a .CSV file.


Research

I have found numerous programs that let me batch export the meta data of the PDF, but this typically has to do with the source information and not the information available about the PDF itself.


Details

I need the page numbers to be able to deduce the order of pages. I'm using for an indexing system that will allow two parties to locate and communicate about the documents. I plan to have an Excel document with the document titles and unique IDs that will need to correspond to sequential bates numbers on PDFs.

I don't mind coding or getting extensively creative with this, but it has to be something that can be done in batch as there are many many files.

Thank you in advance for any help you can provide.

You said you don't mind coding, so here's a short Python script that does what you want (as I understand it).

#!python3.6
import csv
import os

import fitz  # http://pymupdf.readthedocs.io/en/latest/


def main():
    """ Place script in same directory as PDFs. """
    script_dir = os.path.dirname(os.path.abspath(__file__))
    csv_filename = os.path.join(script_dir, 'pdf_information.csv')
    with open(csv_filename, mode='w', newline='') as f:
        writer = csv.writer(f)
        writer.writerow([
            'Filename',
            'Page Count',
        ])
        for basename in os.listdir(script_dir):
            if basename.upper().endswith('.PDF'):
                filename = os.path.join(script_dir, basename)
                pdf = fitz.open(filename)
                writer.writerow([
                    basename,
                    pdf.pageCount,
                ])
                pdf.close()


if __name__ == '__main__':
    main()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM