PageOrientation partially ignored?
Tobias Oelgarte
tobias.oelgarte at gmail.com
Tue Aug 18 08:39:31 UTC 2020
I created a minimal example to illustrate the issue. If I print with
'orientation' set to PORTRAIT i get the expected result [1]. But if i
print with 'orientation' set to LANDSCAPE, then i still get a page in
portrait orientation and with mixed up margins [2]. Picture [3]
illustrates what i would expect.
=========
[1] https://pasteboard.co/JmUr91w.png (Portrait)
[2] https://pasteboard.co/JmUryc2.png (Landscape actual result)
[3] https://pasteboard.co/JmUsc04.png (Landscape expected result)
=========
public class TestApp extends Application {
private final PageOrientation orientation = PageOrientation.LANDSCAPE;
@Override
public void start(Stage stage) throws Exception {
Button printButton = new Button("Print Example Page");
Scene scene = new Scene(printButton);
stage.setScene(scene);
Rectangle rect = new Rectangle(0,0,null);
rect.setStrokeType(StrokeType.INSIDE);
rect.setStrokeWidth(4);
rect.setStroke(Color.RED);
Circle circle = new Circle(0, 0, 40, null);
circle.setStrokeWidth(4);
circle.setStroke(Color.BLUE);
Group group = new Group(rect, circle);
printButton.setOnAction(e -> {
Printer printer = Printer.getDefaultPrinter();
PrinterJob job = PrinterJob.createPrinterJob(printer);
System.out.println(printer);
System.out.println("Supports A4 paper: " + printer.getPrinterAttributes().getSupportedPapers().contains(Paper.A4));
System.out.println("Supports Portrait: " + printer.getPrinterAttributes().getSupportedPageOrientations().contains(PageOrientation.PORTRAIT));
System.out.println("Supports Landscape: " + printer.getPrinterAttributes().getSupportedPageOrientations().contains(PageOrientation.LANDSCAPE));
PageLayout layout = printer.createPageLayout(Paper.A4, orientation, 160, 40, 20, 80);
job.getJobSettings().setPageLayout(layout);
layout = job.getJobSettings().getPageLayout();
System.out.println(layout);
rect.setWidth(layout.getPrintableWidth());
rect.setHeight(layout.getPrintableHeight());
boolean success = job.printPage(group);
if (success) {
job.endJob();
}
});
stage.show();
}
public static void main(String[] args) {
Application.launch(TestApp.class, args);
}
}
On 18.08.2020 06:42, Phil Race wrote:
> what printer, driver, and os?
> did you call any methods to verify the values being passed are supported ?
>
> -Phil.
>
>> On Aug 17, 2020, at 9:01 PM, Tobias Oelgarte <tobias.oelgarte at gmail.com> wrote:
>>
>> I just experimented with the JavaFX printing API and I'm confused about the results.
>>
>> If I request to print in landscape format the resulting page is still in portrait mode, but rotated by 90 degrees and with mirrored borders/margins. Is this intentional or should I file a bug report?
>>
>> Simplified Example:
>>
>> Printer printer = Printer.getDefaultPrinter();
>> PageLayout layout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, 80, 20, 10, 40);
>> PrinterJob job = PrinterJob.createPrinterJob(printer);
>> job.getJobSettings().setPageLayout(layout);
>> boolean success = job.printPage(someNode);
>> if (success) {
>> job.endJob();
>> }
>>
>> What i would expect would be an A4 page in landscape orientation, with a top border (long side) of 10, a bottom border of 40, a left border of 80 and a right border of 20. The content/node will not be rotated.
>>
>> But what i get is the following. The paper size is A4 as requested. The orientation is portrait (not as requested). The top border (long side) is 40, the bottom border is 10, the left border is 20, the right border is 80. The content/node is rotated by 90 degrees to the left.
>>
>> My guess is that the orientation is partially ignored, resulting in the confusing margins.
>>
>> --
>> Tobias Oelgarte
>> Mail: tobias.oelgarte at gmail.com
More information about the openjfx-dev
mailing list