Add Different Groups of Elements to PDF
Adding Different groups of elements to PDF is simple and easy.
How to Add Group to PDF in C#
The following steps and sample code illustrate adding a Group to a PDF document using DynamicPDF Core Suite.
Steps for Adding Group to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to Document instance. - Create a
Group
object. - Add the required elements to the group (rectangle, line, etc.,).
- Add the Group instance to the Page instance.
- 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 in C#
Multiple page elements can be added to an Anchor Group and the group to the PDF document. The following steps and sample code illustrate adding a Group to a PDF document using DynamicPDF Core Suite.
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 (rectangle, line, etc.,).
- Add the AnchorGroup instance to the Page instance.
- 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 in C#
Adding an AreaGroup to a PDF using DynamicPDF Core Suite is straightforward. The following steps and sample code add an AreaGroup to a PDF document using DynamicPDF Core Suite.
Steps for Adding an AreaGroup to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to Document instance. - Create a
AreaGroup
object. - Add needed elements to the AreaGroup (rectangle, line, etc.,).
- Add the AreaGroup instance to the Page instance.
- 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#
Adding TransformationGroup to PDF using DynamicPDF Core Suite is straightforward. The following steps and sample code illustrate adding a TransformationGroup to a PDF document using DynamicPDF Core Suite.
Steps for Adding TransformationGroup to PDF Document
- Create a
Document
object. - Create a
Page
object and add it to Document instance. - Create a
TransformationGroup
object and add theRectangle
object andLabel
object to it. - Vertically scale the group.
- Add the TransformationGroup instance to the Document instance.
- 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 in C#
Adding a TransparencyGroup to a PDF using DynamicPDF Core Suite is straightforward. The following steps and sample code illustrate adding a TransparencyGroup to a PDF document using DynamicPDF Core Suite.
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 the Page instance. - Vertically scale the group.
- Add the TransparencyGroup instance to the Page instance.
- 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
Clone or view the example project at GitHub. This example code above is in the Examples/GroupExample.cs file.
Getting Started
NuGet Package
DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is using the Visual Studio Package Manager, but you can also download the package directly from NuGet.
DynamicPDF Core Suite Information
More information on DynamicPDF Core Suite can be found on its website.
Available on Other Platforms
DynamicPDF Core Suite is available for the following platforms. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX