0

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

Samael
  • 81
  • 2
  • 3
  • You can do a `TableView.snapshot()` on your table, where the return type is WriteableImage. The problem with an image in your pdf is, that it is an image and not selectable text. But there is a bug in there, when trying to make it a image format like, for more info see here: http://stackoverflow.com/a/30995307/4170073 – aw-think Jul 11 '16 at 17:50

1 Answers1

0

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)

Samael
  • 81
  • 2
  • 3