I am trying to decorate the attached PDF using Aspose.PDF 23.2, although when I add a rectangle to it, I get an OutOfMemory error (after a long time). Previously I was able to draw FloatingBoxes using the pageRect dimensions:
var doc = new Document("demo.pdf"); var page = doc.getPages().get_Item(1); page.getPageInfo().setMargin(new MarginInfo(0,0,0,0)); var pageRect = page.getPageRect(true); var graph = new Graph((float) pageRect.getWidth(), (float) pageRect.getHeight()); graph.setTop(0); graph.setLeft(0); var rectangle = new Rectangle(791, 545, 50, 50); rectangle.getGraphInfo().setFillColor(Color.getRed()); graph.getShapes().add(rectangle); page.getParagraphs().add(graph); doc.save("test.pdf");
Checking the page dimensions, I observed that PageInfo is bringing coordinates as if the document was rotated, apart from the decimals difference:
- 841.680000 x 595.440000
- 595.000000 x 842.000000
If I create the Graph using the PageInfo coordinates, the OutOfMemory error do not occur, but then the rectangle is not drawn into the right place.
If I set PageInfo dimensions based on PageRect dimensions, the error goes away and the rectangle appears in the right positions.
- Is setting PageInfo with/height a valid work around? How does it impact the document itself?
- Why do we have such dimension difference if PageInfo returns false for Landscape and Page returns 0 for the rotation?demo.pdf (28.8 KB)