For the complete documentation index, see llms.txt. This page is also available as Markdown.

Images and shapes

Images and vector shapes are inline content: they are added to a paragraph and participate in the text flow. In fact an image is a shape - AddImage creates a shape and sets the image as its background.

Images

AddImage takes the display size in points and either a file path or a filter. The image is scaled to the requested size.

Paragraph para = doc.AddParagraph();
para.SetJustificationMode(Paragraph.TextJustification.e_center);
para.AddImage(120, 90, input_path + "butterfly.png");
Paragraph para = doc.AddParagraph();
para.SetJustificationMode(Paragraph::e_text_justify_center);
para.AddImage(120, 90, input_path + "butterfly.png");
para := doc.AddParagraph()
para.SetJustificationMode(ParagraphE_text_justify_center)
para.AddImage(120, 90, inputPath+"butterfly.png")
Paragraph para = doc.addParagraph();
para.setJustificationMode(Paragraph.TextJustification.e_text_justify_center);
para.addImage(120, 90, input_path + "butterfly.png");
const para = await doc.addParagraph();
para.setJustificationMode(PDFNet.Paragraph.TextJustification.e_text_justify_center);
await para.addImage(120, 90, inputPath + 'butterfly.png');
PTParagraph* para = [doc AddParagraph];
[para SetJustificationMode:e_ptpara_text_justify_center];
[para AddImageWithPath:120 height:90
                  path:[input_path stringByAppendingString:@"butterfly.png"]];
$para = $doc->AddParagraph();
$para->SetJustificationMode(Paragraph::e_text_justify_center);
$para->AddImage(120, 90, $input_path."butterfly.png");
Image of a blue butterfly.

Because images are inline, they can sit in the middle of running text - useful for logos, icons and signatures.

An icon inline with text.

An overload of AddImage accepts a filter, so the image data can come from memory rather than disk. To place an image outside the text flow, pinned to a page position with text wrapping around it, put it in a float.

Shape types

AddShape takes a shape type and a size. Type-specific properties such as the corner radius and the arrow head size are ignored by shapes for which they do not apply.

Examples of shapes like a square, oval, and arrow.

Shape values include:

Value
Shape

e_line

Plain line

e_line_arrow

Line with an arrow head at one end

e_line_double_arrow

Line with arrow heads at both ends

e_rectangle

Rectangle

e_rectangle_rounded_corners

Rectangle with rounded corners

e_oval

Ellipse

e_arrow

Solid arrow

Shape text boxes

Every shape exposes a ContentContainer through GetTextBox. Anything you can put in a document can go inside a shape, which is how mastheads, callouts, and pull quotes are built.

Blue container with The Monthly Dispatch written in white.

Info

A shape does not grow to fit its text box. Size the shape for the content you expect, or keep the text short.

Rotation and flipping

SetRotation rotates a shape, together with its text box and background image, around its center. SetFlipHorizontal and SetFlipVertical mirror it.

Green arrows that are rotated, pointing in different directions.

Further Reading

  • Floats for taking an image or shape out of the text flow.

  • Paragraphs and text for the paragraph that hosts inline images and shapes.

Last updated

Was this helpful?