We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Position of draw a rectangle

Hi,
I use the following code to draw a rectangle

        Document mRes = new Document();
        mRes.Pages.Add();
        Page page = mRes.Pages[1];
        var canvas = new Aspose.Pdf.Drawing.Graph((float)mRes.PageInfo.Width, (float)mRes.PageInfo.Height);
        page.Paragraphs.Add(canvas);
        Aspose.Pdf.Drawing.Rectangle myRec = new Aspose.Pdf.Drawing.Rectangle(0, 738, 180, 100);
        var c = ColorTranslator.FromHtml("#0099ff");
        myRec .GraphInfo.Color = Aspose.Pdf.Color.FromRgb(c);
        myRec .Text = new TextFragment("Some Text");
        myRec .Text.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(c);
        canvas.Shapes.Add(myRec );
        mRes.Save(resultPath);

As far as I know, the rectangle should be draw at the very left side of the page since I set x = 0, but it’s not.
It has about 80 offset from the left side.
Is there anything wrong in my code?

Thanks,

@anthonyding

Thanks for contacting support.

The offset was occurring due to default margin values inside PDF page. Please set margins to zero, in order to draw rectangle to the extreme left.

page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);

Rectangle.pdf (1.9 KB)

Thanks, that works perfectly.