Image and Inline Text

Hi,


You have the sample code in GitHub - aspose-pdf/Aspose.PDF-for-.NET: Aspose.PDF for .NET examples, plugins and showcase projects to create a PDF with text and inline image (see below code). How do you make the image to appear in the left first?

Thanks,
Joseph

string dataDir = @"C:\Users\Documents";

// Instantiate Pdf instance by calling its empty constructor
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
// Create section object and add it to sections collection of PDF
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

// Create a text object
Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text();
// Add text object to paragraphs collection of section
sec1.Paragraphs.Add(text1);
// Add sample text to segments collection of text object
text1.Segments.Add(“This is a test for inline”);
// 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.
Aspose.Pdf.Generator.Image img1 = new Aspose.Pdf.Generator.Image();
// Specify the image file path
img1.ImageInfo.File = dataDir + “aspose.Pdf-for-.net-logo.jpg”;
// Indicate seg2’s InlineParagraph is a image.
seg2.InlineParagraph = img1;
dataDir = dataDir + “InlineImage_out_.pdf”;
// Create the result PDF Document
pdf1.Save(dataDir);

Hi Joseph,

Thanks for using our API’s and sorry for the delayed response.

In order to accomplish your requirement, please try using following code snippet. For your reference, I have also attached the output generated over my end.

[C#]

string dataDir = @"C:\pdftest";

// Instantiate Pdf instance by calling its empty constructor

Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();

// Create section object and add it to sections collection of PDF

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

// Create a text object

Aspose.Pdf.Generator.Text text1 = new Aspose.Pdf.Generator.Text();

// 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.

Aspose.Pdf.Generator.Image img1 = new Aspose.Pdf.Generator.Image();

// Specify the image file path

img1.ImageInfo.File = "c:/pdftest/logoSpin.jpg";

// 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");

dataDir = dataDir + "InlineImage_out_.pdf";

// Create the result PDF Document

pdf1.Save(dataDir);