Hey there, map enthusiasts and Python coders! 👋 This repo contains two nifty scripts that'll help you work with large PDF maps. Whether you're dealing with gigantic geological surveys, city plans, or just really, really big treasure maps, I've got you covered.
pdf_splitter.py: This bad boy takes your massive PDF map and cuts it into manageable A0-sized tiles.tile_stitcher.py: Once you're done working with your tiles, this script puts Humpty Dumpty back together again.
Ever tried opening a 14GB PDF file? Yeah, it's not fun. These scripts let you:
- Work with sections of large maps without melting your computer
- Process or edit parts of a map independently
- Reassemble your map after making changes
Before you dive in, make sure you have these installed:
- Python 3.x
- PyMuPDF (fitz)
- Pillow (PIL)
You can install the required packages with:
pip install PyMuPDF Pillow-
Open
pdf_splitter.py -
Scroll to the bottom and update these lines:
input_pdf = 'path/to/your/large_map.pdf' output_directory = 'path/to/output/tiles'
Examples:
- For Unix-based systems (macOS, Linux):
input_pdf = '/Users/yourusername/Documents/large_map.pdf' output_directory = '/Users/yourusername/Documents/map_tiles'
- For Windows:
input_pdf = r'C:\Users\yourusername\Documents\large_map.pdf' output_directory = r'C:\Users\yourusername\Documents\map_tiles'
Note for Windows users: The
rbefore the string makes it a raw string, which treats backslashes as literal characters. - For Unix-based systems (macOS, Linux):
-
Run the script:
python pdf_splitter.py
-
Watch as your map gets sliced and diced into A0-sized PNG tiles!
-
Open
tile_stitcher.py -
At the bottom, update these lines:
input_directory = 'path/to/input/tiles' output_file = 'path/to/output/stitched_map.png'
Examples For Unix-based systems (macOS, Linux) and Windows are as mentioned above.
-
Run the script:
python tile_stitcher.py
-
Marvel at your reassembled map!
- Handles ridiculously large PDF files (we're talking gigabytes)
- Splits maps into standard A0-sized tiles
- Stitches tiles back together, even if they're not all the same size
- Provides verbose output so you know exactly what's happening
- Currently works with single-page PDF maps
- Assumes your map is in the first page of the PDF
- Outputs tiles as PNG files (great quality, but can be large)
Found a bug? Have an idea for an improvement? Want to add support for A1 tiles because you think A0 is just showing off? Feel free to open an issue or submit a pull request!
This project is licensed under the MIT License - see the LICENSE file for details.
- Hat tip to the PyMuPDF and Pillow teams for their awesome libraries
- Thanks to caffeine for making this project possible
Happy mapping! 🗺️