This API endpoint allows you to rotate a specific page of a PDF file. It uses the PyPDF2 library to perform the rotation.
POST /rotate_pdf
-
details
: An object containing the rotation details.page
(integer): The page number to rotate.degree
(integer): The rotation angle in degrees.
-
file
: The PDF file to rotate.
The API response will include the following:
-
response
(string): A message indicating whether the PDF rotation was successful. -
path
(string): The path of the rotated PDF file.
-
Read the input rotation details and the PDF file.
-
Use the PyPDF2 library to open the PDF file.
-
Create a new PDF writer object.
-
Get the specified page from the PDF.
-
Rotate the page using the
rotateClockwise
method and the specified rotation degree. -
Add the rotated page to the PDF writer.
-
Write the output PDF file using the PDF writer.
-
Close the output file.
-
Return the API response with the message indicating the success of the rotation and the path of the rotated PDF file.
That's it! With these implementation steps, you can rotate a specific page of a PDF file using this API endpoint.