PDF Displacing rectangle?

Hello I am running some tests on Aspose PDF (.Net), I am working on a service that requires a good deal of control where things are placed in the page.

And I found that creating a rectangle (same size as boxes) in a page where the media box and the crop box are the same, ends up creating a rectangle in the wrong location. The following code:

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();
Aspose.Pdf.Drawing.Graph graph = new Graph(page.MediaBox.Width, page.MediaBox.Height);
Aspose.Pdf.Drawing.Rectangle r = new Aspose.Pdf.Drawing.Rectangle((float)page.MediaBox.LLX, (float)page.MediaBox.LLY, (float)page.MediaBox.Width, (float)page.MediaBox.Height);
r.GraphInfo.FillColor = Aspose.Pdf.Color.Azure;
graph.Shapes.Add(r);
page.Paragraphs.Add(graph);
doc.Save("test.pdf");

generates the following pdf. Notice the displacement of the rectangle. My expectation was: the rectangle should be covering the media and crop pages. Where is the displacement added? Can I change it?

Thanks!
test.pdf (1.5 KB)

@jose.cornado

You need to honor the Page Margins as well while adding the rectangle. When you add new page in the document, it gets added with the default margins value i.e. 72points = 1inch. Please check below code snippet where we set margins to zero and obtained correct output:

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();
page.PageInfo.Margin = new Aspose.Pdf.MarginInfo(0, 0, 0, 0);
Aspose.Pdf.Drawing.Graph graph = new Graph(page.MediaBox.Width, page.MediaBox.Height);
graph.Margin = new Aspose.Pdf.MarginInfo(0, 0, 0, 0);
Aspose.Pdf.Drawing.Rectangle r = new Aspose.Pdf.Drawing.Rectangle((float)page.MediaBox.LLX, (float)page.MediaBox.LLY, (float)page.MediaBox.Width, (float)page.MediaBox.Height);
r.GraphInfo.FillColor = Aspose.Pdf.Color.Azure;
graph.Shapes.Add(r);
page.Paragraphs.Add(graph);
doc.Save(dataDir + "test.pdf");

test.pdf (1.5 KB)

Perfect Thanks a lot!