Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Следующий фрагмент кода также работает с библиотекой Aspose.PDF.Drawing.
Aspose.PDF for .NET поддерживает функцию добавления графических объектов (например, графика, линии, прямоугольника и т.д.) в PDF-документы. Вы также получаете возможность добавить объект Rectangle, где вам также предлагается возможность заполнить объект прямоугольника определённым цветом, управлять Z-порядком, добавить градиентную заливку цветом и т. д.
Давайте сначала рассмотрим возможность создания объекта Rectangle.
Выполните следующие шаги:
Создайте новый PDF документ.
Добавьте страницу в коллекцию страниц PDF-файла.
Добавьте фрагмент текста в коллекцию абзацев экземпляра страницы.
Создайте экземпляр Graph.
Установите границу для рисунка.
Создайте объект Rectangle.
Добавьте объект Rectangle в коллекцию фигур объекта Graph.
Добавьте графический объект в коллекцию абзацев экземпляра страницы.
Добавьте фрагмент текста в коллекцию абзацев экземпляра страницы.
Сохраните ваш 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 также предлагает возможность заполнения объекта прямоугольника определённым цветом.
В следующем фрагменте кода показано, как добавить объект Rectangle, который заполнен цветом.
// 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");
}
}
Посмотрите на результат заполнения прямоугольника сплошным цветом:
Aspose.PDF for .NET поддерживает возможность добавления графических объектов в PDF-документы, и иногда требуется заполнить графические объекты градиентом цвета. Чтобы заполнить графические объекты градиентом цвета, нам нужно установить setPatterColorSpace с объектом gradientAxialShading следующим образом.
В следующем фрагменте кода показано, как добавить объект Rectangle, который заполнен градиентом цвета.
// 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 поддерживает заполнение объекта прямоугольника определённым цветом. Объект прямоугольника также может иметь альфа-канал цвета для придания прозрачного вида. В следующем фрагменте кода показано, как добавить объект Rectangle с альфа-каналом цвета.
Пиксели изображения могут хранить информацию об их непрозрачности вместе со значением цвета. Это позволяет создавать изображения с прозрачными или полупрозрачными областями.
Вместо того чтобы делать цвет прозрачным, каждый пиксель хранит информацию о том, насколько он непрозрачен. Эти данные о непрозрачности называются альфа-каналом и обычно хранятся после цветовых каналов пикселя.
// 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 поддерживает функцию добавления графических объектов (например, график, линия, прямоугольник и т.д.) в PDF-документы. При добавлении более одного экземпляра одного и того же объекта внутрь PDF-файла мы можем управлять их рендерингом, указывая порядок Z. Порядок Z также используется, когда нам нужно отобразить объекты друг над другом.
В следующем фрагменте кода показаны шаги для отображения объектов Rectangle друг над другом.
// 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.