在很多场合下文本和图片经常需要一起使用,增加客户对文档的阅读性,这种方式一般叫做文本和内联图片,保持文本和图片在同一行,并且可以控制图片和文本的相对位置。
Aspose.Pdf是一款功能强大的PDF文档类处理控件,不仅可以创建、编辑和提取PDF文档,还可以转换PDF文档为多种格式,使用该产品开发人员在创建PDF文档时设置图片和文本的内联,可以设置图片在文本的左边或者右边,具体使用代码和效果可以参考下面的详细代码:
// Instantiate Pdf instance by calling its empty constructor
// Create section object and add it to sections collection of PDF
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
// Create a text object
// Add text object to paragraphs collection of section
sec1.Paragraphs.Add(text1);
// Create segment 2 and add it to segements collection of text object
Aspose.Pdf.Generator.Segment seg2 = text1.Segments.Add();
// Create a Image object to contain logo gif.
// Specify the image file path
img1.ImageInfo.File = "logo.png";
// Indicate seg2's InlineParagraph is a image.
seg2.InlineParagraph = img1;
// Add sample text to segments collection of text object
text1.Segments.Add("This is a test for inline");
// Create the result PDF Document
pdf1.Save("InlineImage_out_.pdf");