Rendering form fields
📌 Overview
Form fields, such as text boxes, buttons etc. are not normally included when rendering a page. This is because they don't form part of the page content per se - they are annotations, similar to comments and other markup.
📗 Instructions
To include annotations on the page, their appearance streams must be added to the page content. You can do this with some simple code:
🪜 Steps
Find annotations: use
IPage::getAnnotations()
and filter by annotation type.Add appearance streams to page content: use
IAnnotation::getAppearance()
followed byIAnnotationAppearance::getScaledAppearance()
to get the scaled appearance.
⌨️ Sample Code
Here is a function that applies the steps described above to a page.
void flattenAnnotation(const IPagePtr& page, const IAnnotation::eAnnotationType& annotationType)
{
CAnnotationVect annotations = page->getAnnotations();
for (const auto& annotation : annotations)
{
if (annotation->getType() == annotationType)
{
const IAnnotationAppearancePtr appearance = annotation->getAppearance(eAUNormal);
page->edit()->appendChild(appearance->getScaledAppearance(annotation->getRect()));
}
}
}
As we only want to render form fields, you call this method with eATWidget as the filter:
// Flatten form fields
flattenAnnotation(page, IAnnotation::eATWidget);
This method should be applied to the IPage
, before rendering.
☑️ Conclusion
Rendering form fields in Mako involves incorporating their appearance streams into the page content, as they are considered annotations. By following the outlined steps and using the provided sample code, users can effectively render form fields such as text boxes and buttons. This process ensures that annotations are visually represented on the page, enhancing the document's interactivity and usability.
📚 Additional Resources
If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.