'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.DrawingImports GCDRAW = GrapeCity.Documents.Drawing '' This sample shows how to insert arbitrary objecs (images in this sample)'' into a block of text so that those objects keep their positions relative'' to the surrounding text, and are laid out exactly like other text runs,'' and can participate in text flow.PublicClassInlineImagesFunctionCreatePDF(ByVal stream AsStream) AsInteger'' Get the images to use as inline objects:Using imgPuffins AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "puffins-small.jpg")), imgFerns AsGCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "ferns-small.jpg"))'' The image alignment to use:Dim ia = NewImageAlign(ImageAlignHorz.Center, ImageAlignVert.Bottom, True, True, True, False, False)'' Create and set up the document:Dim doc = NewGcPdfDocument()Dim page = doc.NewPage()Dim g = page.Graphics'' Create and set up a TextLayout object to print the text:Dim tl = g.CreateTextLayout() tl.MaxWidth = page.Size.Width tl.MaxHeight = page.Size.Height tl.MarginLeft = 36 tl.MarginRight = 36 tl.MarginTop = 36 tl.MarginBottom = 36 tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12 tl.DefaultFormat.BackColor = Color.LightGoldenrodYellow tl.TextAlignment = TextAlignment.Justified'' Create inline objects using the images and arbitrary sizes:Dim ioPuffins = NewInlineObject(imgPuffins, 36, 24)Dim ioFerns = NewInlineObject(imgFerns, 36, 24)'' Build up the text: tl.Append("The 'Inline objects' feature of the TextLayout class allows inserting arbitrary objects" +"into a block of text. Those objects are then treated exactly like other text runs, " +"and keep their positions relative to the surrounding text. " +"In this sample, we insert some images into the text as inline objects, " +"use the TextLayout class to position them along with text, and draw them " +"using the GcGraphics.DrawImage method.") tl.Append("Here are some puffins:") tl.Append(ioPuffins) tl.Append("and here are some ferns:") tl.Append(ioFerns) tl.Append("The end.")'' Debug.Assert(tl.InlineObjects.Count = 0, "InlineObjects is filled by RecalculateGlyphs")'' This method fetches and measures the glyphs needed to render the text,'' because we draw the same text a few times with different layout,'' we call this once before the loop below: tl.RecalculateGlyphs()'' Debug.Assert(tl.InlineObjects.Count = 2, "InlineObjects is filled by RecalculateGlyphs")'' In a loop, draw the text and inline images in 3 different locations'' and bounds on the page:For i = 0To2 tl.MarginTop = tl.ContentRectangle.Bottom + 36 tl.MarginLeft = 36 + 72 * i tl.MarginRight = 36 + 72 * i'' Note passing 'false' here, we do not need to recalc the glyphs because'' the text has not changed: tl.PerformLayout(False)'' Draw the text and images: g.DrawTextLayout(tl, PointF.Empty)ForEach inlineObj In tl.InlineObjects g.DrawImage(CType(inlineObj.Object, GCDRAW.Image), inlineObj.ObjectRect.ToRectangleF(), Nothing, ia)NextNext'''' Done: doc.Save(stream)Return doc.Pages.CountEndUsingEndFunctionEndClass