Up to now, I have used different types of packages in Python to extract information from PDF files, but I couldn't find a way to measure the margins of the PDF document. As an example, I wanted to get the size of the margins on the four sides of the pdf page.
I have used pdfcrop package to remove the white spaces(margins) but couldn't measure the margin size.
Example using PyMuPDF
If someone is interested to extend the above to all possible page content - nd not just text or image, use the even faster method
page.get_bboxlog(). This won't read or extract anything, instead only returns covered rectangles. The above loop would then be: