Related questions
Concept explainers
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
Step by stepSolved in 3 steps
- In Python IDLE: In the attached image is a class. I have used highlighter to outline a small segment of the code. I want to know- what does this portion of code do? What is the purpose of this code segment? Why do I need this peice of code?arrow_forwardI have tried this however, I am getting an error. What do I do?arrow_forwardFirst, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "CharCounter" (without the quotation marks) that gets two Strings called inputEntry and inputCharacter from the user at the command line. Allow for the inputEntry String to be one or more words of input. Check that the inputCharacter String has a length of 1 and note these validations: If it doesn't, provide the user with suitable feedback and conclude the program. If the inputCharacter length is valid (i.e., it has a length of 1), use a while loop to check each position in the inputEntry variable and return the number of times the character occurs. For example, if the inputEntry is "test" and the inputCharacter is "e" you would output: "There is 1 occurrence(s) of 'e' in test."arrow_forward
- Refer to the following interface: Provide two examples (screenshots) that in many ways could improve the above or similar interface using the principles of direct manipulation. Explain the relevant improvements as well. (Examples might have different object, labels and organization)arrow_forwardUsing comments within the code itself, can you provide an line by line explanation of the below JavaScript file? The file itself deals with WebGl and if that helps you. Please & thank you JavaScript File: function inverse2(m) { var a = mat2(); var d = det2(m); a[0][0] = m[1][1]/d; a[0][1] = -m[0][1]/d; a[1][0] = -m[1][0]/d; a[1][1] = m[0][0]/d; return a; } function inverse3(m) { var a = mat3(); var d = det3(m); var a00 = [ vec2(m[1][1], m[1][2]), vec2(m[2][1], m[2][2]) ]; var a01 = [ vec2(m[1][0], m[1][2]), vec2(m[2][0], m[2][2]) ]; var a02 = [ vec2(m[1][0], m[1][1]), vec2(m[2][0], m[2][1]) ]; var a10 = [ vec2(m[0][1], m[0][2]), vec2(m[2][1], m[2][2]) ]; var a11 = [ vec2(m[0][0], m[0][2]), vec2(m[2][0], m[2][2]) ]; var a12 = [ vec2(m[0][0], m[0][1]), vec2(m[2][0], m[2][1]) ]; var a20 = [...arrow_forwardCan some pretty please help with this HW problem?arrow_forward
- I need a code that demonstrates the use of the below items (Templates, overloading, and vectors). It doesn't need to be special and you can choose the example for the code. Maybe 30 - 50 lines of code that I can run in Visual Basic 2019. I just want to be able to compile it so that I understand what I am reading next week. Working examples are better than what I can pull from the single code examples in the book. Please label to help me identify. Thanks 1. Write C++ code (perhaps around 30-50 lines of code) and make it compile and run showing how to use: a. Templates b. Overloading c. Vectorsarrow_forwardhow to write a method that reads in any csv file and extracts the data from the csv file into header and the remaining data using the csv module, and stores them in instance variables. also how to write a code to handle potential errors with file content such as empty file and file not found in python?arrow_forwardIn python: The program should ask users for their email address and password for connecting to the mail server. You can create a new gmail account and use it for this assignment. Once the connection is complete, the program should ask for the receiver''s email address, and lastly send the email. Write "Hello" for the subject and "Email from Python" as body. Use the getpass library to hide password from shell. Instantiate an object and call it. Submit the .py file as well as screenshots showing the code runs and email received.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education