09-26-2024, 06:29 AM
I wrote a simple Python script to produce a .CSV file that can be imported into MobileSheets with the PDF file to create separate pieces. It uses the very imperfect method of assuming that all piece titles are in a specific font and size. This is very 'rough and ready' and works for me by manually editing it to change the input PDF file and the title font as needed. This was only ever intended for my personal use and is very far from being a 'production ready' program.
The only dependency is py-pdf-parser, which can be installed using pip.
The .CSV file is output to the terminal by default, but can be redirected to a files using the ">" operator (E.g. "python3 splitpdfmusic.py > OUTPUT_FILE.csv".)
The only dependency is py-pdf-parser, which can be installed using pip.
The .CSV file is output to the terminal by default, but can be redirected to a files using the ">" operator (E.g. "python3 splitpdfmusic.py > OUTPUT_FILE.csv".)
Code:
# Generate index for MobileSheets
from py_pdf_parser.loaders import load_file
from py_pdf_parser.visualise import visualise
document = load_file("FILE PATH HERE")
#print(document.fonts) # Uncomment to display a list of fonts used in the document
headers = document.elements.filter_by_font("LDOJID+Verdana-Bold,9.8") # Change font and size here
print("title;pages")
for h in headers:
s = h.text().split('\n')[0]
print(f'"{s}";{h.page_number}-{h.page_number}')
#visualise(document) # Uncomment for debugging