JDK-8177387 : The document can not be printed out after setting landscape option
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8,9,11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,windows
  • CPU: x86
  • Submitted: 2017-03-16
  • Updated: 2018-08-22
  • Resolved: 2018-08-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbd_majorResolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Testsuite name: Swing Functional
Test name(s):Swing_JEditorPane/Manual/TextDocumentPrintingDemo
Product(s) tested:open JDK9b160 (64bit)
OS/architecture:oel7.1-Redhat-x64


Issue:
1.After setting the landscape option in 'Print Options' menu, the document can not be print out.

Comments
Seems like in TextComponentPrintable#calculateRowMetrics(), when we get rect = printShell.modelToView(i); it returns rect.height as 0 in landscape mode for openjdk because of which no entry is added in rowMetrics which then subsequently fails in this check in TextComponentPrintable#printOnEDT() because size is 0 amd pageIndex is also 0 if (pagesMetrics.size() <= pageIndex) { return NO_SUCH_PAGE; } thereby not printing any page. Height being returned as 0 seems to be a similar problem as in https://bugs.openjdk.java.net/browse/JDK-8139178: Wrong fontMetrics when printing in Landscape (OpenJDK)
24-03-2017

Following test prints in landscape mode in openjdk9. So, it seems to do with JTextCompoment or text layouting as we call setText() in the problematic testcase. import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Path2D; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.MediaTray; import javax.print.attribute.standard.OrientationRequested; public class LandscapeStackOverflow implements Printable { public static final void main(String[] parameters) { PrinterJob printjob = PrinterJob.getPrinterJob(); printjob.setJobName("Test Print Job"); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(OrientationRequested.LANDSCAPE); boolean print = printjob.printDialog(attributes); if (!print) { return; } try { printjob.setPrintable(new LandscapeStackOverflow()); printjob.print(attributes); } catch (PrinterException exception) { exception.printStackTrace(); } } public int print(Graphics graphics, PageFormat format, int index) { if (index > 0) return NO_SUCH_PAGE; String orientation = null; if (format.getOrientation() == 0) { orientation = "Landscape"; } else if (format.getOrientation() == 1) { orientation = "Portrait"; } graphics.drawString(orientation, 100, 100); graphics.drawString(System.getProperty("java.version"), 100, 150); return PAGE_EXISTS; } }
24-03-2017

Reproducible in 8GA and 7b146.
24-03-2017

Observations: In ubuntu16.04 with RicohAficioMP5002 printer, Oracle JDK9 b162 works ok for both portrait and landscape.mode. Openjdk9 b162 works ok for portrait mode but does not print anything in landscape mode. Same observations in windows7 for jdk9b162.
23-03-2017

Yes, it doesn't work for me, too, but please, could you be more specific about how exactly the document can not be printed out? I'm attaching a small snippet. On my Windows 10 system, the printer job is reported sent but the printer does nothing (it prints OK with Oracle b160). On my Ubuntu 14.04 with b160 RI it prints an empty page while with a promoted b155 and with b163 PIT it prints as expected.
22-03-2017

Year, after we double check it on win10, there is the same issue without any exception, the document can not be printed out.
21-03-2017