Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: bin2pdf.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script converts a binary file (.bin) to a PDF file (.pdf).
- It reads the binary data from the file and converts it to a string representation.
- The binary string is then written to a PDF file with each binary digit in a separate cell.
- Requirements:
- - Python 3.x
- - FPDF library (install using: pip install fpdf)
- Usage:
- 1. Save this script as 'bin2pdf.py'.
- 2. Ensure your binary file ('example.bin') is in the same directory as the script.
- 3. Install the FPDF library using the command: 'pip install fpdf'
- 4. Run the script.
- 5. The converted PDF file ('bin2pdf.pdf') will be generated in the same directory.
- Note: Adjust the 'bin_filename' and 'pdf_filename' variables in the script as needed.
- """
- from fpdf import FPDF
- def bin_to_pdf(bin_filename, pdf_filename):
- with open(bin_filename, 'rb') as binfile:
- binary_data = binfile.read()
- pdf = FPDF()
- pdf.add_page()
- pdf.set_font("Arial", size=12)
- # Convert binary data to a string representation
- binary_string = ''.join(format(byte, '08b') for byte in binary_data)
- # Write binary string to PDF
- pdf.multi_cell(0, 10, binary_string)
- pdf.output(pdf_filename)
- if __name__ == "__main__":
- # Set the filenames for the binary and PDF files
- bin_filename = 'example.bin'
- pdf_filename = 'bin2pdf.pdf'
- # Convert the binary file to a PDF file
- bin_to_pdf(bin_filename, pdf_filename)
- print(f"Converted '{bin_filename}' to '{pdf_filename}'.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement