Advertisement
Python253

pdf2bin

Mar 14th, 2024
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: pdf2bin.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script converts a PDF file (.pdf) to a binary file (.bin).
  10. It reads the PDF content and writes it directly to the binary file.
  11.  
  12. Requirements:
  13. - Python 3.x
  14.  
  15. Usage:
  16. 1. Save this script as 'pdf2bin.py'.
  17. 2. Ensure your PDF file ('example.pdf') is in the same directory as the script.
  18. 3. Run the script.
  19.  
  20. Note: Adjust the 'pdf_filename' and 'bin_filename' variables in the script as needed.
  21. """
  22.  
  23. def pdf_to_bin(pdf_filename, bin_filename):
  24.     with open(pdf_filename, 'rb') as pdf_file, open(bin_filename, 'wb') as bin_file:
  25.         bin_file.write(pdf_file.read())
  26.  
  27. if __name__ == "__main__":
  28.     # Set the filenames for the PDF and binary files
  29.     pdf_filename = 'example.pdf'
  30.     bin_filename = 'pdf2bin.bin'
  31.  
  32.     # Convert the PDF to a binary file
  33.     pdf_to_bin(pdf_filename, bin_filename)
  34.  
  35.     print(f"Converted '{pdf_filename}' to '{bin_filename}'.")
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement