List of usage examples for com.itextpdf.layout Document Document
public Document(PdfDocument pdfDoc)
From source file:qcas.EndTestController.java
@FXML public void displayPdf() { FileChooser chooser = new FileChooser(); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("PDF file(*.pdf)", " *.pdf "); chooser.getExtensionFilters().add(extFilter); File file = chooser.showSaveDialog(new Stage()); try {/* w w w . ja va2 s. com*/ WritableImage img = StudentResult.snapshot(null, null); ImageData imgData = ImageDataFactory.create(SwingFXUtils.fromFXImage(img, null), null); com.itextpdf.layout.element.Image pdfImg = new com.itextpdf.layout.element.Image(imgData); System.out.println("Entered 3 "); PdfWriter writer = new PdfWriter(new FileOutputStream(file)); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); doc.add(new Paragraph("Hello world, " + "this is a test pdf file.")); doc.add(pdfImg); doc.close(); } catch (Exception exc) { exc.printStackTrace(); } }
From source file:quiz.results.view.QuizSummaryViewController.java
/** * * @param e/*from ww w. ja v a 2 s . c o m*/ */ @FXML public void saveToPdf(ActionEvent e) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF files", "*.pdf")); File file = chooser.showSaveDialog(application.stage); if (file != null) { try { // take the snapshot of the result frame and add it to the pdf WritableImage img = resultFrame.snapshot(null, null); ImageData imgData = ImageDataFactory.create(SwingFXUtils.fromFXImage(img, null), null); com.itextpdf.layout.element.Image pdfImg = new com.itextpdf.layout.element.Image(imgData); PdfWriter writer = new PdfWriter(new FileOutputStream(file)); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); doc.add(pdfImg); doc.close(); } catch (Exception exc) { exc.printStackTrace(); } } }
From source file:quiz.student.result.NoOfTestTakenController.java
/** * This method exports the statistics to pdf * @param e ActionEvent//from w ww . j a va 2s.co m */ @FXML public void viewStats(ActionEvent e) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().add(new ExtensionFilter("PDF files", "*.pdf")); File file = chooser.showSaveDialog(application.stage); if (file != null) { try { WritableImage img = Display.snapshot(null, null); ImageData imgData = ImageDataFactory.create(SwingFXUtils.fromFXImage(img, null), null); com.itextpdf.layout.element.Image pdfImg = new com.itextpdf.layout.element.Image(imgData); PdfWriter writer = new PdfWriter(new FileOutputStream(file)); PdfDocument pdfDoc = new PdfDocument(writer); Document doc = new Document(pdfDoc); doc.add(pdfImg); doc.close(); } catch (Exception exc) { exc.printStackTrace(); } } }
From source file:ru.waytosky.itext.Main.java
public static void main(String[] args) throws FileNotFoundException, MalformedURLException { // Document document = new Document(PageSize.A4, 20, 20, 20, 20); // PdfWriter.getInstance(document, new FileOutputStream("C:/test.pdf")); // document.open(); // Image image = Image.getInstance(getClass().getResource("/logo.png")); // document.add(image); // document.close(); //Initialize PDF writer String dest = "hello.pdf"; PdfWriter writer = new PdfWriter(dest); //Initialize PDF document PdfDocument pdf = new PdfDocument(writer); // Initialize document Document document = new Document(pdf); //Add paragraph to the document Image image = new Image(ImageDataFactory.create("darksouls.jpg")); // Image.getInstance(getClass().getResource("/logo.png")); document.add(image);//from www . j av a2s . c om //Close document document.close(); }
From source file:Utils.PdfUtil.java
public void writeDocument() { try {// w w w. ja v a2s. c o m PdfWriter writer = new PdfWriter(createDestination()); PdfDocument pdf = new PdfDocument(writer); Document document = new Document(pdf); mCommonFont = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN); addTitle(document); addContent(document); addFooter(document); document.close(); } catch (Exception ex) { Logger.getLogger(PdfUtil.class.getName()).log(Level.SEVERE, null, ex); } }