List of usage examples for com.lowagie.text Document close
boolean close
To view the source code for com.lowagie.text Document close.
Click Source Link
From source file:appli_etudiants.ExportPDF.java
public static void main(Etudiants etudiant) throws SQLException, FileNotFoundException, BadElementException, IOException { try {//from www . j a v a 2s.com Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:/tesPDF.pdf")); document.open(); PdfContentByte canvas = writer.getDirectContentUnder(); Image image = Image.getInstance("c:/fond_cv.jpg"); image.setAbsolutePosition(0, 80); canvas.saveState(); PdfGState state = new PdfGState(); state.setFillOpacity(0.6f); canvas.setGState(state); canvas.addImage(image); canvas.restoreState(); LineSeparator lineSepa = new LineSeparator(); lineSepa.setLineColor(new Color(21, 96, 189)); Paragraph para1 = new Paragraph(); Paragraph para2 = new Paragraph(etudiant.getAdresse_rue()); Paragraph para3 = new Paragraph(etudiant.getAdresse_cp() + " " + etudiant.getAdresse_ville()); Paragraph para4 = new Paragraph(etudiant.getCourriel(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189))); Paragraph para5 = new Paragraph(etudiant.getTel_personnel()); Paragraph para6 = new Paragraph(etudiant.getTel_professionnel()); Paragraph para7 = new Paragraph(etudiant.getSite_web()); para1.add(new Chunk(etudiant.getPrenom(), FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD, new Color(21, 96, 189)))); para1.add( new Chunk(" " + etudiant.getNom(), FontFactory.getFont(FontFactory.HELVETICA, 20, Font.BOLD))); Image image1 = Image.getInstance(DaoS4.getPhoto()); image1.scalePercent(50); image1.setAlignment(Image.RIGHT | Image.TEXTWRAP); image1.scaleAbsolute(94, 94); document.add(image1); document.add(para1); document.add(para2); document.add(para3); document.add(para4); document.add(para5); document.add(para6); para7.setSpacingAfter(25f); document.add(para7); Paragraph para8 = new Paragraph(DaoS4.getLibelleTitre()); para8.setSpacingBefore(25f); para8.setSpacingAfter(20f); document.add(para8); Paragraph para9 = new Paragraph(new Chunk("EXPERIENCE PROFESSIONELLE", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)))); para9.setSpacingBefore(15f); para9.setSpacingAfter(15f); document.add(para9); document.add(lineSepa); Paragraph para10 = new Paragraph(DaoS4.getLibelleExpPro()); para10.setSpacingAfter(15f); document.add(para10); Paragraph para11 = new Paragraph(new Chunk("FORMATION", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)))); para11.setSpacingBefore(15f); para11.setSpacingAfter(15f); document.add(para11); document.add(lineSepa); Paragraph para12 = new Paragraph(DaoS4.getLibelleFormation()); para12.setSpacingAfter(15f); document.add(para12); Paragraph para13 = new Paragraph(new Chunk("INFORMATIQUE", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)))); para13.setSpacingBefore(15f); para13.setSpacingAfter(15f); document.add(para13); document.add(lineSepa); Paragraph para14 = new Paragraph(DaoS4.getLibelleInformatique()); para14.setSpacingAfter(15f); document.add(para14); Paragraph para15 = new Paragraph(new Chunk("LANGUE", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)))); para15.setSpacingBefore(15f); para15.setSpacingAfter(15f); document.add(para15); document.add(lineSepa); Paragraph para16 = new Paragraph(DaoS4.getLibelleLangue()); para16.setSpacingAfter(15f); document.add(para16); Paragraph para17 = new Paragraph(new Chunk("CENTRES D'INTERET", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(21, 96, 189)))); para17.setSpacingBefore(15f); para17.setSpacingAfter(15f); document.add(para17); document.add(lineSepa); Paragraph para18 = new Paragraph(DaoS4.getLibelleInteret()); para18.setSpacingAfter(15f); document.add(para18); document.close(); } catch (DocumentException ex) { Logger.getLogger(ExportPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:at.granul.mason.collector.ChartFileScalarDataWriter.java
License:Open Source License
public static void exportGraph(XYChartGenerator chart, String prefix, int width, int height) { try {//from w w w . j a v a 2 s. co m Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".pdf"))); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); //PdfTemplate tp = cb.createTemplate(width, height); //Write the chart with all datasets chart.addLegend(); /*LegendTitle title = new LegendTitle(chart.getChart().getPlot()); title.setLegendItemGraphicPadding(new org.jfree.ui.RectangleInsets(0,8,0,4)); chart.addLegend(title);*/ LegendTitle legendTitle = chart.getChart().getLegend(); legendTitle.setPosition(RectangleEdge.BOTTOM); Graphics2D g2 = cb.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.getChart().draw(g2, rectangle2D); g2.dispose(); //PNG Output ChartUtilities.saveChartAsJPEG(new File(prefix + "_" + DataWriter.DF.format(new Date()) + ".png"), chart.getChart(), width, height); chart.getChart().removeLegend(); //tp = cb.createTemplate(width, height); //All invisible final XYItemRenderer renderer = chart.getChartPanel().getChart().getXYPlot().getRenderer(); for (int a = 0; a < chart.getSeriesCount(); a++) { renderer.setSeriesVisible(a, false); } final Dataset seriesDataset = chart.getSeriesDataset(); XYSeriesCollection series = ((XYSeriesCollection) seriesDataset); for (int a = 0; a < chart.getSeriesCount(); a++) { renderer.setSeriesVisible(a, true); final String seriesName = series.getSeries(a).getKey() + ""; chart.setYAxisLabel(seriesName); document.newPage(); g2 = cb.createGraphics(width, height * (a + 2), new DefaultFontMapper()); g2.translate(0, height * (a + 1)); chart.getChart().draw(g2, rectangle2D); g2.dispose(); //PNG Output ChartUtilities.saveChartAsJPEG( new File(prefix + "_" + seriesName + DataWriter.DF.format(new Date()) + ".png"), chart.getChart(), width, height); renderer.setSeriesVisible(a, false); } //cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:at.htlpinkafeld.beans.AlleAbwesenheitenBean.java
/** * pdf post processing// w w w. j a va 2 s .c o m * * @param document pdf document * @throws DocumentException */ public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\n\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); pdf.close(); }
From source file:at.htlpinkafeld.beans.JahresuebersichtBean.java
/** * post processes the PDF for creating/*from w ww . j a v a 2 s . c o m*/ * * @param document pdf-doc * @throws DocumentException may be thrown */ public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); pdf.close(); }
From source file:at.htlpinkafeld.beans.UserDetailsBean.java
public void postProcessPDF(Object document) throws DocumentException { Document pdf = (Document) document; pdf.add(new Paragraph("\nStand: " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy")))); User curr = BenutzerverwaltungService.getUserByUsername(selectedUser); UserHistoryService.getUserHistoryEntriesForUserBetweenDates(curr, selectedDate, selectedDate.plusDays(1)) .forEach((uhe) -> {/*from www. j a va 2s .c om*/ monthOvertime = uhe.getOvertime(); }); pdf.add(new Paragraph("\nberstunden gesamt: " + monthOvertime)); pdf.close(); }
From source file:at.htlpinkafeld.beans.UserDetailsBean.java
public void createPDF() { try {//w w w.j av a2 s. c o m FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); if (!document.isOpen()) { document.open(); } preProcessPDF(document); PdfPTable pdfTable = exportPDFTable(); document.add(pdfTable); postProcessPDF(document); //Keep modifying your pdf file (add pages and more) document.close(); String fileName = "Monatszeiten"; writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (DocumentException ex) { Logger.getLogger(UserDetailsBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:at.tugraz.sss.serv.SSFileU.java
License:Apache License
public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws Exception { OutputStream out = null;/*w ww. j av a 2 s. c o m*/ BufferedReader br = null; try { out = openOrCreateFileWithPathForWrite(pdfFilePath); final Document document = new Document(); final PdfWriter writer = PdfWriter.getInstance(document, out); String line; document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); br = new BufferedReader(new FileReader(new File(textFilePath))); while ((line = br.readLine()) != null) { document.add(new Paragraph(line)); } document.close(); } catch (Exception error) { if (out != null) { out.close(); } if (br != null) { br.close(); } } }
From source file:at.tugraz.sss.serv.SSFileU.java
License:Apache License
public static void writePDFFromDoc(final String docFilePath, final String pdfFilePath) throws Exception { final Document document = new Document(); final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath)); final HWPFDocument word = new HWPFDocument(fs); final WordExtractor we = new WordExtractor(word); final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath); final PdfWriter writer = PdfWriter.getInstance(document, out); final Range range = word.getRange(); document.open();/*from w w w . j a va 2 s .c om*/ writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); String[] paragraphs = we.getParagraphText(); for (int i = 0; i < paragraphs.length; i++) { org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i); // CharacterRun run = pr.getCharacterRun(i); // run.setBold(true); // run.setCapitalized(true); // run.setItalic(true); paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", ""); System.out.println("Length:" + paragraphs[i].length()); System.out.println("Paragraph" + i + ": " + paragraphs[i].toString()); // add the paragraph to the document document.add(new Paragraph(paragraphs[i])); } document.close(); }
From source file:at.tugraz.sss.serv.util.SSFileU.java
License:Apache License
public static void writePDFFromText(final String pdfFilePath, final String textFilePath) throws SSErr { OutputStream out = null;/* w w w.ja v a 2s .com*/ BufferedReader br = null; try { out = openOrCreateFileWithPathForWrite(pdfFilePath); final Document document = new Document(); final PdfWriter writer = PdfWriter.getInstance(document, out); String line; document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); br = new BufferedReader(new FileReader(new File(textFilePath))); while ((line = br.readLine()) != null) { document.add(new Paragraph(line)); } document.close(); } catch (Exception error) { SSServErrReg.regErrThrow(error); } finally { if (out != null) { try { out.close(); } catch (IOException ex) { SSLogU.err(ex); } } if (br != null) { try { br.close(); } catch (IOException ex) { SSLogU.err(ex); } } } }
From source file:at.tugraz.sss.serv.util.SSFileU.java
License:Apache License
public static void writePDFFromDoc(final String docFilePath, final String pdfFilePath) throws SSErr { try {//ww w . j a v a 2 s.c o m final Document document = new Document(); final POIFSFileSystem fs = new POIFSFileSystem(openFileForRead(docFilePath)); final HWPFDocument word = new HWPFDocument(fs); final WordExtractor we = new WordExtractor(word); final OutputStream out = openOrCreateFileWithPathForWrite(pdfFilePath); final PdfWriter writer = PdfWriter.getInstance(document, out); final Range range = word.getRange(); document.open(); writer.setPageEmpty(true); document.newPage(); writer.setPageEmpty(true); String[] paragraphs = we.getParagraphText(); for (int i = 0; i < paragraphs.length; i++) { org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i); // CharacterRun run = pr.getCharacterRun(i); // run.setBold(true); // run.setCapitalized(true); // run.setItalic(true); paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", ""); System.out.println("Length:" + paragraphs[i].length()); System.out.println("Paragraph" + i + ": " + paragraphs[i].toString()); // add the paragraph to the document document.add(new Paragraph(paragraphs[i])); } document.close(); } catch (Exception error) { SSServErrReg.regErrThrow(error); } }