I would like to determine the angle of inclination of the text in my PDF document (in order to align this document as a result). I receive a PDF document scanned by people, and accordingly, this document will not be perfectly aligned. There are cases when the document is completely upside down, it happens at a slight angle, sometimes at an angle of about 100-120 degrees. In general, as an input, I can get a document rotated absolutely under any degree (from 0 to 360).
The content of the document is printed text and tables (handwritten text may occur, but we will not take this into account).
As I understand it, in order to determine the angle of the entire document (for further alignment), I need to determine the angle of the text. However, here it must be borne in mind, for example, that if the document is rotated 180 degrees, the angle of the text is 0 degrees, but I still have to somehow understand that the document needs to be turned over.
I have been looking for a solution for quite a long time, but I could not find a more or less acceptable result. I really appreciate the community's help!
Below I present examples of documents that I receive (but I reformatted them beforehand, since I could not upload the PDF here)
[1]: https://i.stack.imgur.com/muGJN.png [2]: https://i.stack.imgur.com/yTvzM.png
[3]: https://i.stack.imgur.com/gTy6B.jpg [4]: https://i.stack.imgur.com/shrzq.png