简体   繁体   中英

I am trying to get my Borderpane's center data and turn it to a BufferedImage or an Image

I am coding in FXML scenebuilder and I am trying to get my TableView(in borderpane center) and put it in a PDF. I am using iText and create a PDF, put some image to it but I can't get my Borderpane's data or TableView.

@FXML
TableView<ItemList> table;
@FXML
TableColumn<ItemList, String> tableName;
@FXML
TableColumn<ItemList, String> tableCount;
@FXML
TableColumn<ItemList, String> tablePrice;
@FXML
TableColumn<ItemList, String> tableTotal;
@FXML
private BorderPane dneme;

My table is in the center of borderpane. I tried dneme.getCenter().getScene().getWindow() or table.getScene().getWindow() I tried it without getCenter(), getScene() or getWindow() too.

My program has a table, data will add in to it and I only want get my table and put it to PDF. Only table is in the center of borderpane. enter image description here

Thanks for your help. I found same thing while I was trying and it worked most of for me. My problem is, it get the screen snapshot but it is not fit the frame of my pdf. I cut some part of it but as I said, it worked. I used

    WritableImage image = dneme.getCenter().snapshot(new SnapshotParameters(), null);
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, new FileOutputStream("ImagesBOTTOMPDF.pdf"));
        document.open();

        File outputfile = new File("d.png");
        ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", outputfile);

        Image imageRight = Image.getInstance("d.png");
        document.add(imageRight);

    } catch (FileNotFoundException | DocumentException i) {
        System.err.println(i.getMessage());
    }
    document.close();

I guess I change the frame little bit and problem will solve. It turns to png file of my snapshot and png looks good but when it export to pdf, it changes frame. (Sorry for my bad English)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM