Created
September 22, 2023 23:04
-
-
Save wtfcarlos/854432c70aff6e6e5b4dac3ec887852e to your computer and use it in GitHub Desktop.
Carlos PDF Compressor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import PyPDF2 | |
| def compress_pdf(input_path, output_path): | |
| with open(input_path, 'rb') as input_pdf: | |
| reader = PyPDF2.PdfReader(input_pdf) | |
| writer = PyPDF2.PdfWriter() | |
| for page_num in range(len(reader.pages)): | |
| page = reader.pages[page_num] | |
| writer.add_page(page) | |
| with open(output_path, 'wb') as output_pdf: | |
| writer.write(output_pdf) | |
| compress_pdf('/Users/carlos/Desktop/input.pdf', '/Users/carlos/Desktop/output.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment