List of usage examples for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream
public PDPageContentStream(PDDocument document, PDPage sourcePage, AppendMode appendContent, boolean compress) throws IOException
From source file:src.view.controller.ContextMenuController.java
/** * Bouton de validation d'ajout d'image//from ww w. j a va2s . c o m * * @param docFile * @param tempImage * @return */ public static MenuItem validateImage(DocFile docFile, ImagePDF tempImage) { MenuItem validate = new MenuItem(TRANSLATOR.getString("VALIDATE")); validate.setOnAction((event) -> { try { PDDocument document = docFile.getDocument(); PDPage page = docFile.getCurrentPage(); PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true); ImageController ic = new ImageController(); ic.addImage(document, contentStream, tempImage); contentStream.close(); TabDisplayer.refreshOpenedTab(); INSTANCE.setNoTool(); TraceDisplayer.getTrace().setMouseTransparent(true); } catch (IOException e) { System.out.println(e.toString()); } }); return validate; }
From source file:src.view.controller.MainController.java
public void testAddImage() { try {/* w w w. ja v a2s. c o m*/ ImageController imageController = new ImageController(); // Chargement du document File file = new File(TEST_DOC_TITLE + ".pdf"); PDDocument document = PDDocument.load(file); document.addPage(new PDPage()); PDPageContentStream contentStream = new PDPageContentStream(document, document.getPage(document.getNumberOfPages() - 1), PDPageContentStream.AppendMode.APPEND, true); // Ajout d'une image sur la deuxime page imageController.addImage(document, contentStream, TEST_IMG_NAME, 100, 400, 0.2f); contentStream.close(); document.save(TEST_DOC_TITLE + ".pdf"); document.close(); System.out.println(TRANSLATOR.getString("TEST_IMAGE_ADDED")); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:src.view.controller.MainController.java
public void testAddTable() { try {//from ww w.j av a 2s. c o m TableController tableController = new TableController(); // Chargement du document File file = new File(TEST_DOC_TITLE + ".pdf"); PDDocument document = PDDocument.load(file); document.addPage(new PDPage()); PDPageContentStream contentStream = new PDPageContentStream(document, document.getPage(document.getNumberOfPages() - 1), PDPageContentStream.AppendMode.APPEND, true); // Instanciation d'un tableau Table table = new Table(100, 600, 200, 200); // Gnration du tableau table.generateTable(2, 7); table.addColumns(2); // Rcupration d'une cellule Cell cell = table.getCell(0); // Initialisation du contenu cell.setContent("TEST"); // Affichage du contenu dans la cellule tableController.printCellContent(contentStream, cell, "center", "middle"); // Ajout d'un tableau tableController.printTable(contentStream, table, false); contentStream.close(); document.save(TEST_DOC_TITLE + ".pdf"); System.out.println(TRANSLATOR.getString("TEST_TABLE_ADDED")); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:src.view.controller.ViewTextAreaController.java
public void btnValider() { try {/*w w w. j a va 2 s . c o m*/ DocFile docFile = INSTANCE.getDocFileOpened(); if (cellId == null) { PDDocument document = docFile.getDocument(); PDPage page = docFile.getCurrentPage(); PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true); TextController tc = new TextController(); if (docFile.getTempAreaSelect() != null) { tc.drawArea(contentStream, docFile.getTempAreaSelect(), jTextArea.getText(), (int) comboBoxTailleTextArea.getValue(), (PDType1Font) comboBoxPoliceTextArea.getValue()); } else { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("ERREUR"); alert.setContentText("Veuillez slectionner une zone de texte"); alert.show(); } contentStream.close(); TabDisplayer.refreshOpenedTab(); INSTANCE.setNoTool(); exit(); } else { docFile.getTempTable().getCell(cellId).setContent(jTextArea.getText()); Cell traceCell = docFile.getTraceTable().getCell(cellId); float posX = traceCell.getPosX() + 40; float posY = traceCell.getPosY() + 50; TraceDisplayer.addText(posX, posY, jTextArea.getText()); this.stage.close(); } } catch (IOException e) { System.out.println(e.toString()); } }