Skip to content

Instantly share code, notes, and snippets.

@wtfcarlos
Created September 22, 2023 23:04
Show Gist options
  • Select an option

  • Save wtfcarlos/854432c70aff6e6e5b4dac3ec887852e to your computer and use it in GitHub Desktop.

Select an option

Save wtfcarlos/854432c70aff6e6e5b4dac3ec887852e to your computer and use it in GitHub Desktop.
Carlos PDF Compressor
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