Grouping Page Elements
Group page elements so they are treated as a group when applying a transformation, transparency, or anchoring using DynamicPDF Core Suite for .NET. The following examples illustrate.
How to Add Group to PDF
The following steps and C# sample code illustrate adding a Group to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding Group to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it toDocument
instance. - Create a
Group
object. - Add the required elements to the group.
- Add the
Group
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Group mygroup = new Group();
mygroup.Add( new Rectangle( 0, 0, 200, 200, 3 ) );
mygroup.Add( new Line( 0, 100, 100, 0, 3 ) );
mygroup.Add( new Line( 100, 0, 200, 100, 3 ) );
mygroup.Add( new Line( 200, 100, 100, 200, 3 ) );
mygroup.Add( new Line( 100, 200, 0, 100, 3 ) );
page.Elements.Add( mygroup );
document.Draw("Output.pdf");
How to Add Anchor Group to PDF
The following steps and C# sample code illustrate adding an AnchorGroup
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding Anchor Group to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to Document instance. - Create an
AnchorGroup
object. - Add elements to the group.
- Add the
AnchorGroup
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
AnchorGroup group = new AnchorGroup(200,200,Align.Center,VAlign.Center);
group.Add(new Rectangle(0, 0, 200, 200, 3));
group.Add(new Line(0, 100, 100, 0, 3));
group.Add(new Line(100, 0, 200, 100, 3));
group.Add(new Line(200, 100, 100, 200, 3));
group.Add(new Line(100, 200, 0, 100, 3));
page.Elements.Add(group);
document.Draw("Output.pdf");
How to Add AreaGroup to PDF
The following steps and C# sample code add an AreaGroup
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding an AreaGroup to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it toDocument
instance. - Create a
AreaGroup
object. - Add needed elements to the
AreaGroup
. - Add the
AreaGroup
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
AreaGroup group1 = new AreaGroup(200, 200);
group1.Add(new Rectangle(0, 0, 200, 200, 3));
group1.Add(new Line(0, 100, 100, 0, 3));
group1.Add(new Line(100, 0, 200, 100, 3));
group1.Add(new Line(200, 100, 100, 200, 3));
group1.Add(new Line(100, 200, 0, 100, 3));
page.Elements.Add(group1);
document.Draw("Output.pdf");
How to Add TransformationGroup to PDF in C#
The following steps and C# sample code illustrate adding a TransformationGroup
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding TransformationGroup to PDF Document
- Create a
Document
object. - Create a
Page
object and add it toDocument
instance. - Create a
TransformationGroup
object and add theRectangle
object andLabel
object to it. - Vertically scale the group.
- Add the
TransformationGroup
instance to theDocument
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
TransformationGroup group1 = new TransformationGroup(100, 100, 200, 200, 30);
group1.Add(new Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue));
group1.Add(new Label("This text is inside a TransformationGroup.", 0, 100, 300, 12));
group1.ScaleY = 2;
page.Elements.Add(group1);
document.Draw("Output.pdf");
How to Add TransparencyGroup to PDF
The following steps and C# sample code illustrate adding a TransparencyGroup
to a PDF document using DynamicPDF Core Suite for .NET.
Steps for Adding a TransparencyGroup to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to the Document instance. - Create a
TransparencyGroup
object and add aRectangle
object. - Add a
Label
to thePage
instance. - Vertically scale the group.
- Add the
TransparencyGroup
instance to thePage
instance. - Add the
Document
object'sDraw
method to draw and save the PDF document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
TransparencyGroup group1 = new TransparencyGroup(0.5f);
group1.Add(new Rectangle(0, 0, 75, 75, RgbColor.Blue, RgbColor.Blue));
group1.Add(new Label("This text is inside a TransparencyGroup.", 0, 100, 300, 12));
page.Elements.Add(group1);
document.Draw("Output.pdf");
GitHub Project
Examples are provided in C# and VB.NET. Clone or view the example project at GitHub. This example code above is in the following files.
- C# - GroupingExample.cs
- VB.NET - GroupingExample.vb
Getting Started
Get started easily by installing DynamicPDF Core Suite for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing.
NuGet Package
The easiest way to install DynamicPDF Core Suite is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
DynamicPDF Core Suite Information
DynamicPDF Core Suite for .NET combines creating, merging, and visual report creation into one powerful product for creating PDF documents. It is ideal for anyone who needs to generate PDF documents or reports or work with existing PDFs in their applications. With a free Evaluation Edition to try and with flexible and royalty-free licensing options, why not start using DynamicPDF Core Suite for .NET today!
More Information on Groups
- Refer to the Grouping documentation topic, or
- Chapter 7, Grouping, in the book DynamicPDF Core Suite for .NET by Example available on GitHub.
Available on Other Platforms
DynamicPDF Core Suite is also available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- DynamicPDF Generator
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX
- DynamicPDF Merger
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX