I want to display some information on screen, based on the position of some pdf page being shown. For that, I need to get the position of the page's border, but right now, I only have a very naive and inefficient solution, which consists in taking vertical slices of the window until I detect a 'mostly white' slice, which I take as the searched border:
import win32gui
from win32api import GetSystemMetrics
dc = win32gui.GetDC(0)
width,height=GetSystemMetrics(0),GetSystemMetrics(1)
fraction=200 # This is to reduce the amount of info to be processed
p_height=height/fraction
suma=0 # This variable holds the number of withe pixels of each slice
for i in range(width): # while in screen w
for j in range(int(p_height)): # hile in screen h
if win32gui.GetPixel(dc, i, j*fraction)!=16777215:
pass # pass if pixel is not withe
else:
suma+=1
if suma/p_height>0.4: # if more than 40% of the pixels are white,
print(i)
break
else:
suma=0
This is both slow and not smart. I guess there's a way to get the information I'm looking for without having to literally 'look' at the screen. Any suggestions?
(I use google chrome to open the pdf.)