Hi,
I am having problems with adding a rectangle to a page in an existing document. I am trying to draw a box around the very edge of the page using the following code:
// Open document
Document document = new Document(_dataDir + "sample.pdf");
// Get the first page
Page page = document.getPages().get_Item(1);
// Create a MarginInfo object
MarginInfo mi = new MarginInfo(0, 0, 0, 0);
// Set the page margins
page.getPageInfo().setMargin(mi);
// Get the media box size
Rectangle mb = page.getMediaBox();
// Create a Graph object
Graph g = new Graph(mb.getWidth(), mb.getHeight());
// Set the graph margins
g.setMarginInfo(mi);
// Create a rectangle the size of the page
Rectangle r = new Rectangle(0, 0, mb.getWidth(), mb.getHeight());
// Add it to the Graph object
g.getShapes().add(r);
// Add the graph object to the page
page.getParagraphs().add(g);
document.save(_dataDir + "new.pdf");
My problem is that the rectangle is drawn the correct size but is offset on the page by what looks to be the default margin size:
image.png (15.3 KB)
If I modify my code to add a new page to the document by changing:
Page page = document.getPages().get_Item(1);
To:
Page page = document.getPages().add();
And draw the rectangle on this new page then the rectangle is drawn in the correct position:
image.png (11.5 KB)
How can I position the rectangle at the very edge of the page on the existing page?
Thanks
Steve