Продолжайте печатать, не разрезая мой заголовок столбца таблицы пополам - PullRequest
0 голосов
/ 06 июня 2018

У меня проблемы с печатью таблицы.Заголовки разрезаны пополам следующим образом:
cutting off headers

Это мой код:

@FXML
private void printAllFlowers(ActionEvent event) throws IOException {
    Printer printer = Printer.getDefaultPrinter(); //get the default printer
    javafx.print.PageLayout pageLayout = printer.createPageLayout(Paper.NA_LETTER, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT); //create a pagelayout.  I used Paper.NA_LETTER for a standard 8.5 x 11 in page.
    PrinterJob job = PrinterJob.createPrinterJob();//create a printer job

    if (job.showPrintDialog(tblFlower.getScene().getWindow()))// this is very useful it allows you to save the file as a pdf instead using all of your printer's paper. A dialog box pops up, allowing you to change the "name" option from your default printer to Adobe pdf.
    {
        double pagePrintableWidth = pageLayout.getPrintableWidth(); //this should be 8.5 inches for this page layout.
        double pagePrintableHeight = pageLayout.getPrintableHeight();// this should be 11 inches for this page layout.

        tblFlower.prefHeightProperty().bind(Bindings.size(tblFlower.getItems()).multiply(Bindings.size(tblFlower.getItems()).add(1.0)));// If your cells' rows are variable size you add the .multiply and play with the input value until your output is close to what you want. If your cells' rows are the same height, I think you can use .multiply(1). This changes the height of your tableView to show all rows in the table.
        tblFlower.minHeightProperty().bind(tblFlower.prefHeightProperty());//You can probably play with this to see if it's really needed.  Comment it out to find out.
        tblFlower.maxHeightProperty().bind(tblFlower.prefHeightProperty());//You can probably play with this to see if it' really needed.  Comment it out to find out.


        double scaleX = pagePrintableWidth / tblFlower.getBoundsInParent().getWidth();//scaling down so that the printing width fits within the paper's width bound.

        double numberOfPages = Math.ceil((tblFlower.getPrefHeight() * scaleX) / pagePrintableHeight);//used to figure out the number of pages that will be printed.

        tblFlower.getTransforms().add(new Scale(scaleX, (scaleX)));//scales the printing. Allowing the width to stay within the papers width, and scales the height to do away with skewed letters and images.
        tblFlower.getTransforms().add(new Translate(0, 0));// starts the first print at the top left corner of the image that needs to be printed

        //Since the height of what needs to be printed is longer than the paper's heights we use gridTransfrom to only select the part to be printed for a given page.
        Translate gridTransform = new Translate();
        tblFlower.getTransforms().add(gridTransform);

        //now we loop though the image that needs to be printed and we only print a subimage of the full image.
        //for example: In the first loop we only pint the printable image from the top down to the height of a standard piece of paper. Then we print starting from were the last printed page ended down to the height of the next page. This happens until all of the pages are printed.
        // first page prints from 0 height to -11 inches height, Second page prints from -11 inches height to -22 inches height, etc.
        for (int i = 0; i < numberOfPages; i++) {
            gridTransform.setY(-i * (pagePrintableHeight / scaleX));
            job.printPage(pageLayout, tblFlower);
        }

        job.endJob();//finally end the printing job.
    }

Может кто-нибудь сказать мне, почему он отрезает мои заголовки?

...