'How to crop editable text pdf file using (x,yw,h) co-ordinates?

Lets' say I have two countours,

c = (array([[[   1,  342]],
 
        [[   1,  347]],
 
        [[1705,  347]],
 
        [[1705,  342]]], dtype=int32),
 array([[[ 106,  468]],
 
        [[ 106,  472]],
 
        [[ 107,  473]],
 
        [[1703,  473]],
 
        [[1703,  468]]], dtype=int32))

I am fetching bounding rectangle from contours,

x1,y1,w1,h1 = cv2.boundingRect(c[0])

# print(x1, y1, w1, h1)
# (1, 342, 1705, 6)

Now using these b-box co-ordinates how to crop the original pdf file (not image)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source