Frequently Asked Question
Add a rectangle on a PDF page using RadaeePDF
Last Updated 11 months ago
This code snippet demonstrates how to draw a filled rectangle on a PDF page using the RadaeePDF SDK for Android. The drawRect function takes a Page object, an array of floats representing the rectangle's coordinates (top-left and bottom-right corners), and an integer representing the fill color. The function creates a PageContent object, defines a path for the rectangle using the Path class, fills the path with the specified color, and finally adds the content to the page.
/** * Adds a rectangle to the given page content. * * @param page the pdf page object * @param rect the PDF coordinates of the rectangle to be drawn. * @param fillColor the rectangle fill color */ public static void drawRect(Page page, float[] rect, int fillColor) { PageContent content = new PageContent(); content.Create(); content.GSSave(); // draw a rectangle Path path = new Path(); path.MoveTo(rect[0], rect[1]); path.LineTo(rect[2], rect[1]); path.LineTo(rect[2], rect[3]); path.LineTo(rect[0], rect[3]); path.ClosePath(); //fill it content.SetFillColor(fillColor); content.FillPath(path, true);//using winding fill rule content.GSRestore(); //destroy the path path.Destroy(); //add content to page page.AddContent(content, true); content.Destroy(); }