Check shape bounds in Shapes collection using Python
Contents
[
Hide
]
This article provides a detailed guide on using the bounds-checking feature in the Shapes collection. This feature ensures that elements fit within their parent container and can be configured to throw an exception if the component does not fit.
- Create a new PDF Document
- Add a Page
- Create a Graph
- Create a Rectangle Shape
- Bounds Check Mode
- Add the Rectangle to the Graph
import aspose.pdf as ap
import aspose.pdf.drawing as drawing
import datetime
# Create Document instance
document = ap.Document()
# Add page to pages collection of PDF file
page = document.pages.add()
# Create a Graph object with specified dimensions
graph = ap.drawing.Graph(100, 100)
graph.top = 10
graph.left = 15
graph.border = ap.BorderInfo(ap.BorderSide.BOX, 1, ap.Color.black)
page.paragraphs.add(graph)
# Create a shape object(for example, Rectangle) with specified dimensions
rect = drawing.Rectangle(-1, 0, 50, 50)
rect.graph_info.fill_color = ap.Color.tomato
# Set the BoundsCheck mode to THROW_EXCEPTION_IF_DOES_NOT_FIT
graph.shapes.update_bounds_check_mode(ap.BoundsCheckMode.THROW_EXCEPTION_IF_DOES_NOT_FIT)
# Add the rectangle to the graph
graph.shapes.add(rect)