itext - Save JavaFX ScrollPane content to PDF file -


i'm using below code save content of scrollpane in javafx application pdf file.

button.setonmouseclicked(new eventhandler<mouseevent>() { public void handle(mouseevent event) {  file pdffile = filechooser.showsavedialog(primarystage);  try {     bufferedimage bufimage = swingfxutils.fromfximage(scrollpane.snapshot(new snapshotparameters(), null), null);     fileoutputstream out = new fileoutputstream(new file("../temp.jpg"));     javax.imageio.imageio.write(bufimage, "jpg", out);     out.flush();     out.close();      com.itextpdf.text.image image =com.itextpdf.text.image.getinstance("../temp.jpg");     document doc = new document(new com.itextpdf.text.rectangle(image.getscaledwidth(), image.getscaledheight()));     fileoutputstream fos = new fileoutputstream(pdffile);     pdfwriter.getinstance(doc, fos);     doc.open();     doc.newpage();     image.setabsoluteposition(0, 0);     doc.add(image);     fos.flush();     doc.close();     fos.close();   } catch(exception e) {      e.printstacktrace(); } 

} });

in scrollpane, have long vbox contains 40-50 labels. so, code saves jpg file , adds pdf file.

when temp.jpg created initially, due length, jpg file looks thin. should zoomed see actual content.

when pdf file written, blank except lengthy have been when jpg converted pdf file.

can me fix ? take snapshot of scrollpane pdf actual size/scale ?

i have first scaled image , created document scaled pagesize. fixed issue

com.itextpdf.text.image image =com.itextpdf.text.image.getinstance("../temp.jpg"); image.scalepercent(1); document doc = new document(new com.itextpdf.text.rectangle(image.getscaledwidth(), image.getscaledheight())); doc.open(); doc.add(image); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -