Verificar limites de forma na coleção de Formas
Introdução
Este documento fornece um guia detalhado sobre como usar o recurso de verificação de limites na coleção de Formas. Este recurso garante que os elementos se encaixem dentro de seu contêiner pai e pode ser configurado para lançar uma exceção se o componente não se encaixar.
Pré-requisitos
Você precisará do seguinte:
Visual Studio 2019 ou posterior
Aspose.PDF for .NET 25.3 ou posterior
Um arquivo PDF de exemplo que contenha algumas páginas
Você pode baixar a biblioteca Aspose.PDF for .NET do site oficial ou instalá-la usando o Gerenciador de Pacotes NuGet no Visual Studio.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CheckShapeBounds ()
{
// Create PDF document
using ( var document = new Aspose . Pdf . Document ())
{
// Add page
var page = document . Pages . Add ();
// Create a Graph object with specified dimensions
var graph = new Aspose . Pdf . Drawing . Graph ( 100d , 100d )
{
Top = 10 ,
Left = 15 ,
Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . Box , 1F , Aspose . Pdf . Color . Black )
};
page . Paragraphs . Add ( graph );
// Create a Shape object (for example, Rectangle) with specified dimensions
var rect = new Aspose . Pdf . Drawing . Rectangle (- 1 , 0 , 50 , 50 )
{
GraphInfo =
{
FillColor = Aspose . Pdf . Color . Tomato
}
};
// Set the BoundsCheckMode to ThrowExceptionIfDoesNotFit
graph . Shapes . UpdateBoundsCheckMode ( Aspose . Pdf . BoundsCheckMode . ThrowExceptionIfDoesNotFit );
// Add the rectangle to the graph
graph . Shapes . Add ( rect );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CheckShapeBounds ()
{
// Create PDF document
using var document = new Aspose . Pdf . Document ();
// Add page
var page = document . Pages . Add ();
// Create a Graph object with specified dimensions
var graph = new Aspose . Pdf . Drawing . Graph ( 100d , 100d )
{
Top = 10 ,
Left = 15 ,
Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . Box , 1F , Aspose . Pdf . Color . Black )
};
page . Paragraphs . Add ( graph );
// Create a Aspose.Pdf.Drawing.Shape object (for example, Aspose.Pdf.Drawing.Rectangle) with specified dimensions
var rect = new Aspose . Pdf . Drawing . Rectangle (- 1 , 0 , 50 , 50 )
{
GraphInfo =
{
FillColor = Aspose . Pdf . Color . Tomato
}
};
// Set the BoundsCheckMode to ThrowExceptionIfDoesNotFit
graph . Shapes . UpdateBoundsCheckMode ( Aspose . Pdf . BoundsCheckMode . ThrowExceptionIfDoesNotFit );
// Add the rectangle to the graph
graph . Shapes . Add ( rect );
}