@naresh.mahto
The Graph Shape Rectangle and image stamp are two different things. You cannot add an image stamp inside a shape. You can only draw a shape with text in it. For example, below code:
Document doc = new Document();
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
var canvas = new Drawing.Graph((float)page.PageInfo.Width, (float)page.PageInfo.Height);//tf.Rectangle.Width, pg.PageInfo.Height
//canvas.Margin = new MarginInfo() { Bottom = 0, Left = 0, Right = 0, Top = 0 };
//canvas.Left = 0;
//canvas.Top = 0;
//canvas.Border = new BorderInfo(BorderSide.All, 1f, Color.Black);
page.Paragraphs.Add(canvas);
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 354, 72, 30); //new Aspose.Pdf.Drawing.Rectangle(0, 700, 100, 750);
var c = ColorTranslator.FromHtml("#FFFF00");
//rect.GraphInfo.Color = Aspose.Pdf.Color.FromRgb(c);
//rect.GraphInfo.FillColor = alphaColor;
//canvas.Shapes.Add(rect);
rect.Text = new TextFragment("test address , test address esttest address , test address testtest address , test address test");
rect.GraphInfo.Color = Aspose.Pdf.Color.FromRgb(c);
canvas.Shapes.Add(rect);
doc.Save(dataDir + "rectangle.pdf");
Also, you need to have 4 values of coordinates in order to draw a shape inside PDF Page. Furthermore, Aspose.PDF also offers FloatingBox class that has the feature of border and you can add images as well as text inside it. It takes two coordinates values i.e. Top/Left and you can also set its height and width. Please check below code snippet where we added a floating box along with barcode image and text inside it:
Document doc1 = new Document();
Page Pdfpage = doc1.Pages.Add();
Pdfpage.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);
//coord.X == 306;
//coor.Y = 113;
//labelsize.Width = 306;
//labelsize.Height = 113;
FloatingBox fb = new FloatingBox(306, 113);
fb.Top = 10;
fb.Left = 10;
fb.Border = new BorderInfo(BorderSide.All, Color.Black);
Aspose.Pdf.Image image = new Aspose.Pdf.Image();
image.FixWidth = 150;
image.FixHeight = 100;
image.File = dataDir + "Barcode.jpg";
image.HorizontalAlignment = HorizontalAlignment.Center;
image.VerticalAlignment = VerticalAlignment.Top;
TextFragment textFragment1 = new TextFragment("ABC20220223J11522556");
//// Set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.FontStyle = FontStyles.Bold;
textFragment1.TextState.Font = FontRepository.FindFont("Courier New");
textFragment1.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
textFragment1.HorizontalAlignment = HorizontalAlignment.Center;
textFragment1.VerticalAlignment = VerticalAlignment.Bottom;
fb.Paragraphs.Add(image);
fb.Paragraphs.Add(textFragment1);
Pdfpage.Paragraphs.Add(fb);
doc1.Save(dataDir + "floatingbox.pdf");
floatingbox.pdf (54.0 KB)
Please note that you cannot consider coordinates values the same in both PDFSharp and Aspose.PDF. They both have their own implementation of PDF Coordinating System and separate Classes and Objects to achieve functionality. Please try to understand how Aspose.PDF deals with coordinates and what classes can be used to achieve your requirement and you will be able to create expected PDF document.