Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Le code suivant fonctionne également avec la bibliothèque Aspose.PDF.Drawing.
Aspose.PDF for .NET prend en charge la fonctionnalité d’ajout d’objets graphiques (par exemple graphique, ligne, rectangle, etc.) aux documents PDF. Vous avez également la possibilité d’ajouter un objet Rectangle où vous pouvez également remplir l’objet rectangle avec une certaine couleur, contrôler le Z-Order, ajouter un remplissage de couleur dégradée, etc.
Tout d’abord, examinons la possibilité de créer un objet Rectangle.
Suivez les étapes ci-dessous :
Créez un nouveau Document PDF.
Ajoutez une Page à la collection de pages du fichier PDF.
Ajoutez un fragment de texte à la collection de paragraphes de l’instance de page.
Créez une instance de Graph.
Définissez la bordure pour l’objet de dessin.
Créez une instance de Rectangle.
Ajoutez un objet Rectangle à la collection de formes de l’objet Graph.
Ajoutez l’objet graphique à la collection de paragraphes de l’instance de page.
Ajoutez un fragment de texte à la collection de paragraphes de l’instance de page.
Et enregistrez votre fichier PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddRectangle(Aspose.Pdf.Page page, float x, float y, float width, float height, Aspose.Pdf.Color color, int zIndex)
{
// Create a Graph object with dimensions matching the specified rectangle
var graph = new Aspose.Pdf.Drawing.Graph(width, height)
{
// Prevent the graph from repositioning automatically
IsChangePosition = false,
// Set the Left coordinate position for the Graph instance
Left = x,
// Set the Top coordinate position for the Graph instance
Top = y
};
// Create a Rectangle object inside the Graph
var rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height)
{
// Set the fill color of the rectangle
GraphInfo =
{
FillColor = color,
// Set the border color of the rectangle
Color = color
}
};
// Add the rectangle to the Shapes collection of the Graph
graph.Shapes.Add(rect);
// Set the Z-Index for the Graph object to control layering
graph.ZIndex = zIndex;
// Add the Graph object to the Paragraphs collection of the page
page.Paragraphs.Add(graph);
}
Aspose.PDF for .NET offre également la fonctionnalité de remplir un objet rectangle avec une certaine couleur.
Le code suivant montre comment ajouter un objet Rectangle qui est rempli de couleur.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RectangleFilled()
{
// The path to the documents directory directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Create Graph instance
var graph = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance with specified dimensions
var rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 120)
{
// Specify fill color for the Rectangle object
GraphInfo =
{
FillColor = Aspose.Pdf.Color.Red
}
};
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(rect);
// Save PDF document
document.Save(dataDir + "CreateFilledRectangle_out.pdf");
}
}
Regardez le résultat du rectangle rempli d’une couleur unie :
Aspose.PDF for .NET prend en charge la fonctionnalité d’ajout d’objets graphiques aux documents PDF et il est parfois nécessaire de remplir des objets graphiques avec une couleur dégradée. Pour remplir des objets graphiques avec une couleur dégradée, nous devons définir setPatterColorSpace avec l’objet gradientAxialShading comme suit.
Le code suivant montre comment ajouter un objet Rectangle qui est rempli avec une couleur dégradée.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CreateFilledRectangleGradientFill()
{
// The path to the documents directory directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Create Graph instance
var graph = new Aspose.Pdf.Drawing.Graph(400, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance
var rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, 300, 300);
// Create a gradient fill color
var gradientColor = new Aspose.Pdf.Color();
var gradientSettings = new Aspose.Pdf.Drawing.GradientAxialShading(Aspose.Pdf.Color.Red, Aspose.Pdf.Color.Blue)
{
Start = new Aspose.Pdf.Point(0, 0),
End = new Aspose.Pdf.Point(350, 350)
};
gradientColor.PatternColorSpace = gradientSettings;
// Apply gradient fill color to the rectangle
rect.GraphInfo.FillColor = gradientColor;
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(rect);
// Save PDF document
document.Save(dataDir + "CreateFilledRectangleGradient_out.pdf");
}
}
Aspose.PDF for .NET prend en charge le remplissage d’un objet rectangle avec une certaine couleur. Un objet rectangle peut également avoir un canal de couleur alpha pour donner une apparence transparente. Le code suivant montre comment ajouter un objet Rectangle avec un canal de couleur alpha.
Les pixels de l’image peuvent stocker des informations sur leur opacité ainsi que sur la valeur de couleur. Cela permet de créer des images avec des zones transparentes ou semi-transparentes.
Au lieu de rendre une couleur transparente, chaque pixel stocke des informations sur son opacité. Ces données d’opacité sont appelées canal alpha et sont généralement stockées après les canaux de couleur du pixel.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RectangleFilled_AlphaChannel()
{
// The path to the documents directory directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Create Graph instance
var graph = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create first rectangle with alpha channel fill color
var rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 120)
{
GraphInfo =
{
FillColor = Aspose.Pdf.Color.FromArgb(128, 244, 180, 0)
}
};
// Add the first rectangle to the shapes collection of the Graph object
graph.Shapes.Add(rect);
// Create second rectangle with different alpha channel fill color
var rect1 = new Aspose.Pdf.Drawing.Rectangle(200, 150, 200, 100)
{
GraphInfo =
{
FillColor = Aspose.Pdf.Color.FromArgb(160, 120, 0, 120)
}
};
// Add the second rectangle to the shapes collection of the Graph object
graph.Shapes.Add(rect1);
// Save PDF document
document.Save(dataDir + "CreateFilledRectangle_out.pdf");
}
}
Aspose.PDF for .NET prend en charge la fonctionnalité d’ajout d’objets graphiques (par exemple graphique, ligne, rectangle, etc.) aux documents PDF. Lors de l’ajout de plus d’une instance du même objet dans le fichier PDF, nous pouvons contrôler leur rendu en spécifiant le Z-Order. Le Z-Order est également utilisé lorsque nous devons rendre des objets les uns sur les autres.
Le code suivant montre les étapes pour rendre des objets Rectangle les uns sur les autres.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddRectangleZOrder()
{
// The path to the documents directory directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Set size of PDF page
page.SetPageSize(375, 300);
// Set left and top margins for the page object as 0
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Top = 0;
// Create rectangles with different colors and Z-Order values
AddRectangle(page, 50, 40, 60, 40, Aspose.Pdf.Color.Red, 2);
AddRectangle(page, 20, 20, 30, 30, Aspose.Pdf.Color.Blue, 1);
AddRectangle(page, 40, 40, 60, 30, Aspose.Pdf.Color.Green, 0);
// Save PDF document
document.Save(dataDir + "ControlRectangleZOrder_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.