FormFragment Class
A form fragment in a PDF document.
Namespace: DevExpress.Docs.Pdf
Assembly: DevExpress.Docs.Pdf.v26.1.dll
Declaration
Example
How to: Create a Form Template and Add It to a PDF Document
The following code snippet creates a form template, adds text and a line to it. Then, it creates two form fragments based on the template and adds them to two different pages of a PDF document. Finally, it saves the document as “Result.pdf”.
using DevExpress.Docs.Pdf;
using DevExpress.Drawing;
using DevExpress.Drawing.Printing;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using PdfDocument pdfDocument = new PdfDocument();
var page = pdfDocument.Pages.Add(DXPaperKind.A4);
// Create a form template.
var headerTemplate = new FormTemplate();
headerTemplate.Bounds = new RectangleF(0, 0, ((float)page.Width), 150);
// Add text to the form template.
headerTemplate.AddTextFragment("Company Name: DevExpress", 50, 160);
headerTemplate.AddTextFragment("Invoice Date: " + DateTime.Now.ToShortDateString(), 50, 120);
headerTemplate.AddTextFragment("Invoice Number: 1001", 50, 140);
// Create a line.
GraphicsPath headerLine = new GraphicsPath(new PointF(0, 110));
headerLine.AppendLineSegment(new PointF((float)headerTemplate.Bounds.Width, 110));
var linePath = new GraphicsPath[] { headerLine, };
var lineFragment = new PathFragment();
lineFragment.Fill = Fill.CreateSolid(PdfColor.LightGray);
lineFragment.Paths = linePath;
// Add the line to the form template.
headerTemplate.Fragments.Add(lineFragment);
var secondPage = pdfDocument.Pages.Add(DXPaperKind.A4);
// Create the first form fragment and add it to the first page.
var formFragment = new FormFragment(headerTemplate);
formFragment.Location = new PointF(50, (float)page.Height - 160);
page.AddFormFragment(formFragment);
// Create the second form fragment and add it to the second page.
var formFragment2 = new FormFragment(headerTemplate);
formFragment2.Location = new PointF(100, (float)secondPage.Height - 200);
secondPage.AddFormFragment(formFragment2);
pdfDocument.Save(new FileStream("Result.pdf", FileMode.Create, FileAccess.Write));
Implements
Inheritance
Object
PageFragment
VisualFragment
FormFragment
See Also