You can install PdfItDown by running the following command:
Use PdfItDown within your script
Ypu should initialize PdfItDown by instantiating the Converter
class:
from pdfitdown.pdfconversion import Converter
converter = Converter()
After this, you can use PdfItDown to:
- Convert single files using the
convert
method:
# adding a title for the PDF metadata
converter.convert(file_path = "business_grow.md", output_path = "business_growth.pdf", title="Business Growth for Q3 in 2024")
# without a title
converter.convert(file_path = "logo.png", output_path = "logo.pdf")
- Convert multiple files at once using the
multiple_convert
method:
# with custom output paths
converter.multiple_convert(file_paths = ["business_grow.md", "logo.png"], output_paths = ["business_growth.pdf", "logo.pdf"])
# with inferred output paths
converter.multiple_convert(file_paths = ["business_grow.md", "logo.png"])
- Convert an entire directory at once using the
convert_directory
method:
output_paths = converter.convert_directory(directory_path = "tests/data/testdir")
Be careful: all the documents that you convert need to be supported by PdfItDown, otherwise you’ll see a ValidationError