Details
-
Bug
-
Status: Closed
-
Resolution: Fixed
-
0.92
-
None
-
None
-
Operating System: other
Platform: Other
-
40048
Description
The AWTRenderer.getPageFormat(int) method returns incorrect PageFormat. The
PageFormat contains incorrect imageable area. According to source code imageable
area should be (0, 0, page-width, page-height) but result PageFormat contains
another values.
After analyzing of source code of PageFormat it was determined that
PageFormat.setPaper(Paper) method clones passed Paper and stores reference to
new instance. IMHO, the reason of the bug is that AWTRenderer.getPageFormat(int)
invokes PageFormat.setPaper(Paper) method BEFORE applying of imageable area to
the Paper and as consequence PageFormat clones Paper with default imageable
area. That is, imageable area is applied to another (original, not cloned)
instance of Paper.
The correct code should look like this:
public java.awt.print.PageFormat getPageFormat(int pageIndex)
throws IndexOutOfBoundsException {
try {
if (pageIndex >= getNumberOfPages())
PageFormat pageFormat = new PageFormat();
Paper paper = new Paper();
Rectangle2D dim = getPageViewport(pageIndex).getViewArea();
double width = dim.getWidth();
double height = dim.getHeight();
// if the width is greater than the height assume lanscape mode
// and swap the width and height values in the paper format
if (width > height)
else
{ paper.setImageableArea(0, 0, width / 1000d, height / 1000d); paper.setSize(width / 1000d, height / 1000d); pageFormat.setOrientation(PageFormat.PORTRAIT); } // Set Paper AFTER applying of imageable area.
pageFormat.setPaper(paper);
return pageFormat;
} catch (FOPException fopEx)
}
Attachments
Issue Links
- is duplicated by
-
FOP-1148 Printing from AWT Preview Dialog swallows content because page sizes are wrong
- Closed