Floats
A Float takes its content out of the main document flow and positions it relative to a reference point, with the surrounding content wrapped around it. Floats are how you build pull quotes, side figures, watermarks, and logos that do not disturb the text they sit next to.
Create a float
AddFloat creates a float anchored at a paragraph. The returned object is a content container, so you fill it exactly like a document.
Paragraph para = doc.AddParagraph();
// The float is taken out of the main flow; the paragraph text wraps around it.
Float box = para.AddFloat();
box.SetHorizontalReferencePoint(Float.FloatReferencePoint.e_reference_page);
box.SetVerticalReferencePoint(Float.FloatReferencePoint.e_reference_paragraph);
box.SetPositionX(270);
box.SetPositionY(0);
box.SetObstructionType(Float.FloatObstructionType.e_square);
box.AddParagraph().AddImage(90, 90, input_path + "butterfly.png");
para.AddText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do " +
"eiusmod tempor incididunt ut labore et dolore magna aliqua.");Paragraph para = doc.AddParagraph();
// The float is taken out of the main flow; the paragraph text wraps around it.
Float box = para.AddFloat();
box.SetHorizontalReferencePoint(Float::e_reference_page);
box.SetVerticalReferencePoint(Float::e_reference_paragraph);
box.SetPositionX(270);
box.SetPositionY(0);
box.SetObstructionType(Float::e_square);
box.AddParagraph().AddImage(90, 90, input_path + "butterfly.png");
para.AddText("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
"eiusmod tempor incididunt ut labore et dolore magna aliqua.");
The float is created before the text is added, but the order does not matter: floats are positioned independently of their place in the paragraph.
Reference points
The horizontal and vertical positions are measured from separately chosen reference points, set with SetHorizontalReferencePoint and SetVerticalReferencePoint.
e_reference_page
The page edge. Use for content pinned to a fixed spot on the page.
e_reference_paragraph
The anchoring paragraph. Use for content that travels with the text.
e_reference_character
The exact anchor position within the text.
Mixing reference points in a document is common: a page reference horizontally puts the float in a fixed column, while a paragraph reference vertically keeps it beside the text it belongs to, even when that text moves to another page.
SetPositionX and SetPositionY give the offset in points from the chosen reference points. Y grows downwards.
Obstruction types
SetObstructionType controls how the main content reacts to the float.
e_square
Text wraps around the float's bounding box.
e_tight
Text wraps closely around the float's outline.
e_top_and_bottom
Text stops above the float and resumes below it.
e_behind_text
No wrapping; the float is drawn behind the text.
e_in_front_of_text
No wrapping; the float is drawn over the text.
e_behind_text is the usual choice for watermarks and background artwork, since it leaves the layout of the main content untouched.
Common patterns
There are common patterns used with documents, including patterns around pull quotes and watermarks.
Pull quote
Combine a float with a shape text box to get a styled callout beside the article text.
Watermark
Notes
A float is positioned during pagination, so its final location depends on where the anchoring paragraph ends up.
Floats do not stretch the page. Content placed outside the page area is clipped.
Several floats can be anchored to the same paragraph; position them so they do not overlap.
Further Reading
Images and shapes for the content usually placed inside a float.
Sections, headers and footers for content that repeats on every page instead.
Last updated
Was this helpful?