How to insert a PDEForm into a PDDoc
Estimated Reading Time: 2 MinutesIn the Adobe PDF Library (APDFL), a PDEForm is a subtype of PDEElement. This relationship allows a PDEForm to be treated like any other PDEElement within the PDF Edit (PDE) architecture. Understanding this hierarchy is key to effectively adding, converting, or creating form elements in document content.
Adding a PDEForm to PDEContent
Since a PDEForm is a PDEElement, it can be added directly to the PDEContent of a Page or another PDEForm using the PDEContentAddElem() function.
This process is partially demonstrated in the AddArt sample.
Converting a Page into a PDEForm
When a Page object needs to be encapsulated within a PDEForm, the PDEContentAddPage() function can be used.
This function enables existing page content to be transformed into a form for reuse or for nesting within other document structures.
An example of this process can be found in the ImportPages sample.
Creating a PDEForm from Scratch
No dedicated sample currently exists for creating a PDEForm entirely from scratch. However, the process can be constructed as follows:
- Create a PDEContent object and populate it with PDEElements such as text, images, or paths using PDEContentAddElem().
- Convert the content to a Cos object using PDEContentToCosObj().
- Generate a PDEForm from the Cos object with PDEFormCreateFromCosObj().
- Insert the form into PDEContent using PDEContentAddElem() as demonstrated in the previous sections.
.NET and Java Interfaces
A PDEForm is represented by the Form class which has corresponding Constructor and properties. The sample below adds the Content stream from two document pages to Forms and then adds the Forms to the Content of another page.
Page pageLeft = doc1.GetPage(0);
Page pageRight = doc2.GetPage(0);
Document outputDoc = new Document();
Rect outPageRect = new Rect(0, 0, pageLeft.MediaBox.Width*2, pageLeft.MediaBox.Height);
Page outPage = outputDoc.CreatePage(Document.BeforeFirstPage, outPageRect);
Form pageLeftForm = new Form(pageLeft.Content);
Form pageRightForm = new Form(pageRight.Content);
// add contents of left side to the output page
outPage.Content.AddElement(pageLeftForm);
// add contents of right side to the output page
// reposition the second form by shifting to the right the width of the source page
pageRightForm.Translate(pageRight.MediaBox.Width, 0);
outPage1.Content.AddElement(pageRightForm);
For more information, please contact Datalogics Support.