Hello, I am experimenting with Python. There is a lot of # comments in the code to help me understand it better, but there is an error at line 52 with the input_file PdfFileReader and I do not know how to fix the code. Can you help me? # Import easygui and pypdf2 import easygui as gui # imports easygui from PyPDF2 import PdfFileReader, PdfFileWriter # imports PyPDF2 # 1. Display file selection dialog for opening a PDF file. This allows the user to select a PDF that they can rotate! input_path = gui.fileopenbox( # sets the input path and opens a gui box     title="Select a PDF to rotate...", # sets title     default="*.pdf" # sets the default file type     ) # 2. If user cancels the dialog, exit the program. The program will automatically do this if the user cancels! if input_path is None: # if statement for input path being 'none'     exit() # exits the file # 3. Ask user to select one of 90, 180, or 270 degrees. This is how much they will rotate their selected PDF by! choices = ("90", "180", "270") # degree choices for rotating a PDF degrees = gui.buttonbox( # creates buttonbox gui for degrees     msg="Rotate the PDF clockwise by how many degrees?", # sets the message for the box     title="Choose rotation...", # sets the title for the box     choices=choices, # sets the choices     ) # closes the function # 4. Display a file selection dialog for saving the rotated PDF. This allows the user to select a file to save the PDF they chose to rotate! save_title = "Save the rotated PDF as..." # has the user choose a save title file_type = "*.pdf" # sets the file type to be saved output_path = gui.filesavebox(title=save_title, default=file_type) # sets the output path # 5. If the user tries to save with the same name as the input file: while input_path == output_path: # while statement for input path not being equal to output path     # - Alert the user with a message box that this is not allowed.     gui.msgbox(msg="Cannot overwrite original file!") # creates message box in gui     # - Return to step 4.     output_path = gui.filesavebox(title=save_title, default=file_type) # reverts to step 4, sets the output path # 6. If the user cancels the file save dialog, then exit the program. if output_path is None: # if statement for output path being 'none'     exit() # exits the file # 7. Perform the page rotation: # - Open the selected PDF. input_file = PdfFileReader(input_path) # sets input file and has it read output_pdf = PdfFileWriter() # sets output pdf and has it written # - Rotate all the pages. for page in input_file.pages: # has the file input and pages accounted for     page = page.rotateClockwise(degrees) # rotates the pages clockwise     output_pdf.addPage(page) # sets the pdf to the output with rotated pages # - Save the rotated PDF to the selected file. with open(output_path, "wb") as output_file: # opens the output path and file     output_pdf.write(output_file) # writes to the output file and saves rotated

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello, I am experimenting with Python. There is a lot of # comments in the code to help me understand it better, but there is an error at line 52 with the input_file PdfFileReader and I do not know how to fix the code. Can you help me?

# Import easygui and pypdf2

import easygui as gui # imports easygui
from PyPDF2 import PdfFileReader, PdfFileWriter # imports PyPDF2

# 1. Display file selection dialog for opening a PDF file. This allows the user to select a PDF that they can rotate!

input_path = gui.fileopenbox( # sets the input path and opens a gui box
    title="Select a PDF to rotate...", # sets title
    default="*.pdf" # sets the default file type
    )

# 2. If user cancels the dialog, exit the program. The program will automatically do this if the user cancels!

if input_path is None: # if statement for input path being 'none'
    exit() # exits the file

# 3. Ask user to select one of 90, 180, or 270 degrees. This is how much they will rotate their selected PDF by!

choices = ("90", "180", "270") # degree choices for rotating a PDF
degrees = gui.buttonbox( # creates buttonbox gui for degrees
    msg="Rotate the PDF clockwise by how many degrees?", # sets the message for the box
    title="Choose rotation...", # sets the title for the box
    choices=choices, # sets the choices
    ) # closes the function

# 4. Display a file selection dialog for saving the rotated PDF. This allows the user to select a file to save the PDF they chose to rotate!

save_title = "Save the rotated PDF as..." # has the user choose a save title
file_type = "*.pdf" # sets the file type to be saved
output_path = gui.filesavebox(title=save_title, default=file_type) # sets the output path

# 5. If the user tries to save with the same name as the input file:

while input_path == output_path: # while statement for input path not being equal to output path
    # - Alert the user with a message box that this is not allowed.

    gui.msgbox(msg="Cannot overwrite original file!") # creates message box in gui

    # - Return to step 4.

    output_path = gui.filesavebox(title=save_title, default=file_type) # reverts to step 4, sets the output path

# 6. If the user cancels the file save dialog, then exit the program.

if output_path is None: # if statement for output path being 'none'
    exit() # exits the file

# 7. Perform the page rotation:
# - Open the selected PDF.

input_file = PdfFileReader(input_path) # sets input file and has it read
output_pdf = PdfFileWriter() # sets output pdf and has it written

# - Rotate all the pages.

for page in input_file.pages: # has the file input and pages accounted for
    page = page.rotateClockwise(degrees) # rotates the pages clockwise
    output_pdf.addPage(page) # sets the pdf to the output with rotated pages

# - Save the rotated PDF to the selected file.

with open(output_path, "wb") as output_file: # opens the output path and file
    output_pdf.write(output_file) # writes to the output file and saves rotated 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education