How add image + text + graph in one page

I want add on page photo+ text + and graph circle. At now i hove troubles

  1. Image override my text and i cannot see text. Circle inserts on next page.
    image.jpg (85.8 KB)

             var  doc = new Document();
         var page = doc.Pages.Add();
    
         var bitmap = System.Drawing.Image.FromFile("1.png");
         page.PageInfo.Margin.Bottom = 0;
         page.PageInfo.Margin.Top = 0;
         page.PageInfo.Margin.Left = 0;
         page.PageInfo.Margin.Right = 0;
    
         page.CropBox = new Aspose.Pdf.Rectangle(0, 0, bitmap.Width, bitmap.Height);
         doc.PageInfo.Height = bitmap.Height;
         doc.PageInfo.Width = bitmap.Width;
         Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
         image1.File = "1.png";
    
         page.Paragraphs.Add(image1);
    
         TextBuilder builder = new TextBuilder(page);
         TextParagraph paragraph = new TextParagraph();
         paragraph.SubsequentLinesIndent = 20;
         paragraph.Rectangle = new Aspose.Pdf.Rectangle(100, 300, 200, 700);
         paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
         TextFragment fragment1 = new TextFragment("Hello world\Hello city");
         fragment1.TextState.Font = FontRepository.FindFont("Times New Roman");
         fragment1.TextState.FontSize = 12;
         paragraph.AppendLine(fragment1);
    
         builder.AppendParagraph(paragraph);
    
         Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);
         
         Aspose.Pdf.Drawing.Circle circ = new Aspose.Pdf.Drawing.Circle(30, 30, 30);
         circ.GraphInfo.FillColor = Aspose.Pdf.Color.Green;
         circ.Text = new TextFragment("Sale");
         graph.Shapes.Add(circ);
    
         page.Paragraphs.Add(graph);
    
         doc.Save("aspose.pdf");

it is possible?

@mesteruh

We would surely investigate the feasibility of your requirements. However, could you kindly share following information with us:

  • The image you have shared - is it the expected output your desire?
  • Please share the sample image which you want to add inside PDF document
  • Please share the output PDF document that you have obtained using your shared code snippet

it’s result example
image.jpg (137.1 KB)

this full size image
1.jpg (424.3 KB)

@mesteruh

You can add image using ImageStamp because that way the text and graph elements would be shown on the same page. Please check the following code snippet where we used ImageStamp to add image:

var doc = new Document();
var page = doc.Pages.Add();

var bitmap = System.Drawing.Image.FromFile(dataDir + "1.jpg");
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;

ImageStamp imageStamp = new ImageStamp(dataDir + "1.jpg");
imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Center;
imageStamp.Height = page.PageInfo.Height;
imageStamp.Width = page.PageInfo.Width;

page.AddStamp(imageStamp);

TextBuilder builder = new TextBuilder(page);
TextParagraph paragraph = new TextParagraph();
paragraph.SubsequentLinesIndent = 20;
paragraph.Rectangle = new Aspose.Pdf.Rectangle(100, 300, 200, 700);
paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
TextFragment fragment1 = new TextFragment("Hello world\nHello city");
fragment1.TextState.Font = FontRepository.FindFont("Times New Roman");
fragment1.TextState.FontSize = 12;
paragraph.AppendLine(fragment1);

builder.AppendParagraph(paragraph);

Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);

Aspose.Pdf.Drawing.Circle circ = new Aspose.Pdf.Drawing.Circle(30, 30, 30);
circ.GraphInfo.FillColor = Aspose.Pdf.Color.Green;
circ.Text = new TextFragment("Sale");
graph.Shapes.Add(circ);

page.Paragraphs.Add(graph);

doc.Save(dataDir + "aspose.pdf");

Aspose.pdf (419.0 KB)

In case you need further assistance, please feel free to let us know.

i want alignt text to top right border

@mesteruh

You can add text using TextStamp in such cases as well. For example, please replace your TextBuilder related code with following snippet:

Facades.FormattedText text = new Facades.FormattedText("Hello world");
text.AddNewLineText("Hello city");
TextStamp textStamp = new TextStamp(text);
textStamp.TextState.Font = FontRepository.FindFont("Times New Roman");
textStamp.TextState.FontSize = 12;
textStamp.VerticalAlignment = VerticalAlignment.Top;
textStamp.HorizontalAlignment = HorizontalAlignment.Right;
page.AddStamp(textStamp);

You can also specify XIndent and YIndent properties of text stamp in order to position the text as per your desire.