List of usage examples for com.lowagie.text Document addTitle
public boolean addTitle(String title)
From source file:es.uniovi.asw.personalletter.PDFTextWritter.java
/** * Metadata del documento./*from w ww . j a v a 2 s . c om*/ * @param document Documento en cuestin */ private void addMetaData(Document document) { document.addTitle("My first PDF"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText"); document.addAuthor("Lars Vogel"); document.addCreator("Lars Vogel"); }
From source file:fr.aliasource.webmail.server.export.ConversationExporter.java
License:GNU General Public License
public void exportToPdf(IAccount account, ConversationReference cr, ClientMessage[] cm, OutputStream out) throws ConversationExporterException { try {/*from w w w. j a v a 2 s . com*/ Document document = new Document(PageSize.A4, 22, 22, 80, 72); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setPageEvent(new ConversationPdfEventHandler(account, cr, cm)); // NPP by Tom if (cr.getTitle() != null) { document.addTitle(cr.getTitle()); } else { document.addTitle(""); } document.addAuthor("MiniG"); document.open(); document.add(Chunk.NEWLINE); Set<ClientMessage> scm = new LinkedHashSet<ClientMessage>(); for (int i = 0; i < cm.length; i++) { scm.add(cm[i]); } this.exportMessage(scm, document, false); document.close(); } catch (Exception e) { throw new ConversationExporterException("Cannot export conversation ", e); } }
From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Mthode principale qui gre l'export d'un tableau vers un fichier ODS. * * @param export paramtres du document exporter * @param out flux de sortie/* w w w.j a va2 s.c o m*/ * @throws DocumentException Exception */ public final void exportData(final Export export, final OutputStream out) throws DocumentException { // step 1: creation of a document-object final boolean landscape = export.getOrientation() == Export.Orientation.Landscape; final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 20, 20, 50, 50); // left, // right, // top, // bottom // step 2: we create a writer that listens to the document and directs a // PDF-stream to out createWriter(document, out); // we add some meta information to the document, and we open it final String title = export.getTitle(); if (title != null) { final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } final String author = export.getAuthor(); document.addAuthor(author); document.addCreator(CREATOR); document.open(); try { // pour ajouter l'ouverture automatique de la bote de dialogue // imprimer // (print(false) pour imprimer directement) // ((PdfWriter) writer).addJavaScript("this.print(true);", false); for (final ExportSheet exportSheet : export.getSheets()) { final Table datatable; if (exportSheet.hasDtObject()) { // table datatable = new Table(2); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // data rows renderObject(exportSheet, datatable); } else { // table datatable = new Table(exportSheet.getExportFields().size()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(exportSheet, datatable); // data rows renderList(exportSheet, datatable); } document.add(datatable); } } finally { // we close the document document.close(); } }
From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java
License:Apache License
/** * Mthode principale qui gre l'export d'un tableau vers un fichier ODS. * * @param export paramtres du document exporter * @param out flux de sortie/*from w ww. j a v a2 s . c o m*/ * @throws DocumentException Exception */ public final void exportData(final Export export, final OutputStream out) throws DocumentException { // step 1: creation of a document-object final boolean landscape = export.getOrientation() == Export.Orientation.Landscape; final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 20, 20, 50, 50); // left, right, top, bottom // step 2: we create a writer that listens to the document and directs a PDF-stream to out createWriter(document, out); // we add some meta information to the document, and we open it final String title = export.getTitle(); if (title != null) { final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } final String author = export.getAuthor(); document.addAuthor(author); document.addCreator(CREATOR); document.open(); try { // pour ajouter l'ouverture automatique de la bote de dialogue imprimer (print(false) pour imprimer directement) // ((PdfWriter) writer).addJavaScript("this.print(true);", false); for (final ExportSheet exportSheet : export.getSheets()) { final Table datatable; if (exportSheet.hasDtObject()) { // table datatable = new Table(2); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // data rows renderObject(exportSheet, datatable); } else { // table datatable = new Table(exportSheet.getExportFields().size()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(exportSheet, datatable); // data rows renderList(exportSheet, datatable); } document.add(datatable); } } finally { // we close the document document.close(); } }
From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java
License:Open Source License
private ByteArrayOutputStream exportAsPdf(Experiment3VO experiment, List<Buffer3VO> buffers, Proposal3VO proposal) throws Exception { Document document = new Document(PageSize.A4.rotate(), 10, 10, 20, 20); document.addTitle("exportSamplesView"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); HeaderFooter header = new HeaderFooter( new Phrase(proposal.getTitle() + " " + proposal.getCode() + proposal.getNumber()), false); header.setAlignment(Element.ALIGN_CENTER); header.getBefore().getFont().setSize(8); HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorderWidth(1);//from w ww .ja va 2s . com footer.getBefore().getFont().setSize(6); document.setHeader(header); document.setFooter(footer); document.open(); BaseFont bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED); Font font = new Font(bf, 6); document.add(new Paragraph("Data Acquisition: " + experiment.getName(), font)); document.add(new Paragraph("Type: " + experiment.getType(), font)); document.add(new Paragraph("Date: " + experiment.getCreationDate(), font)); document.add(new Paragraph("Proposal: " + proposal.getCode() + proposal.getNumber(), font)); document.add(new Paragraph("Title: " + proposal.getTitle(), font)); document.add(new Paragraph(" ")); document.add(new Paragraph("Measurements", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getMeasurementTable(experiment, buffers)); document.newPage(); document.add(new Paragraph(" ")); document.add(new Paragraph("Analysis", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getAnalysis(experiment, buffers)); document.newPage(); document.add(this.getImageTable(experiment, buffers)); document.close(); return baos; }
From source file:ispyb.common.util.export.PdfExporterSample.java
License:Open Source License
/** * Exports the file for viewSample for shipment * /*from w w w . j a v a 2 s . c o m*/ * @return * @throws Exception */ public ByteArrayOutputStream exportAsPdf() throws Exception { // create simple doc and write to a ByteArrayOutputStream Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20); document.addTitle("exportSamplesView"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); HeaderFooter header; // header + footer if (viewName != null) header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + " --- " + viewName), false); else header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false); header.setAlignment(Element.ALIGN_CENTER); header.setBorderWidth(1); header.getBefore().getFont().setSize(8); HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorderWidth(1); footer.getBefore().getFont().setSize(6); document.setHeader(header); document.setFooter(footer); document.open(); if (aList.isEmpty()) { document.add(new Paragraph("There is no samples in this report")); document.close(); return baos; } // Create first table for samples int NumColumns = 19; PdfPTable table = new PdfPTable(NumColumns); int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage table.setWidths(headerwidths); table.setWidthPercentage(100); // percentage table.getDefaultCell().setPadding(3); table.getDefaultCell().setBorderWidth(1); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // header PdfPCell cell = new PdfPCell(); table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8))); cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8))); table.addCell(cell); table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8))); table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8))); table.setHeaderRows(1); // this is the end of the table header table.getDefaultCell().setBorderWidth(1); DecimalFormat df1 = new DecimalFormat("#####0.0"); DecimalFormat df2 = new DecimalFormat("#####0.00"); Iterator it = aList.iterator(); int i = 1; String currentContainer = "next"; String nextContainer = "next"; while (it.hasNext()) { table.getDefaultCell().setGrayFill(0.99f); if (i % 2 == 1) { table.getDefaultCell().setGrayFill(0.9f); } BLSample3VO samplefv = (BLSample3VO) it.next(); LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId()); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) nextContainer = samplefv.getContainerVO().getCode(); else nextContainer = "next"; // in the case of view sorted by dewar/container, we add a page break afetr each container if (sortView.equals("2") && !currentContainer.equals(nextContainer)) { document.add(table); table.deleteBodyRows(); document.newPage(); } if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getName() != null) table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCode() != null) table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null && samplefv.getContainerVO().getDewarVO().getCode() != null) table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) { currentContainer = samplefv.getContainerVO().getCode(); table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8))); } else { currentContainer = "current"; table.addCell(""); } if (samplefv.getLocation() != null) table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getSpaceGroup() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellA() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellB() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellC() != null) table.addCell( new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellAlpha() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellBeta() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getCellGamma() != null) table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getCrystalVO().getComments() != null) table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getObservedResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getDiffractionPlanVO() != null && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) { table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()), new Font(Font.HELVETICA, 8))); } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null) table.addCell(new Paragraph( df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getComments() != null && samplefv.getComments() != "") table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (samplefv.getBlSampleStatus() != null) table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8))); else table.addCell(""); if (i % 2 == 1) { table.getDefaultCell().setGrayFill(0.0f); } i++; } document.add(table); document.close(); return baos; }
From source file:it.govpay.web.console.pagamenti.gde.exporter.PdfExporter.java
License:Open Source License
private static void addMetaData(Document document) { document.addTitle("Report Eventi"); document.addSubject("Report Eventi selezionati nella console Govpay"); document.addKeywords("Report, Eventi, Govpay"); document.addAuthor("Govpay"); document.addCreator("Govpay"); }
From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java
License:Open Source License
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LogInterface logger = getLogger(request); String titolo = request.getParameter("titolo"); String descrizione = request.getParameter("descrizione"); String scala = request.getParameter("scala"); String mapx = request.getParameter("mapx"); String mapy = request.getParameter("mapy"); //creo URL alla mappa URL urlMappa = new URL(URLDecoder.decode(request.getParameter("urlMappa"), "UTF-8")); URI uriMappa = null;/*from w ww .java 2 s.c o m*/ try { uriMappa = new URI(urlMappa.getProtocol(), null, urlMappa.getHost(), urlMappa.getPort(), urlMappa.getPath(), urlMappa.getQuery() + "&mode=map&scale=" + scala + "&mapxy=" + mapx + "+" + mapy + "&map_size=500 500", null); logger.info("URI di stampa mappa: " + uriMappa); } catch (URISyntaxException e) { logger.error("URI errore di sintassi", e); } Font BOLD15 = new Font(Font.HELVETICA, 15, Font.BOLD); Font FONT12 = new Font(Font.HELVETICA, 12, Font.NORMAL); Font FONT10 = new Font(Font.HELVETICA, 10, Font.NORMAL); Document doc = new Document(); ; PdfWriter pdf = null; Paragraph par = new Paragraph(); try { //creo il PDF response.setContentType("application/pdf"); pdf = PdfWriter.getInstance(doc, response.getOutputStream()); //attributi file doc.addTitle("Mappa di Prato"); doc.addAuthor("Comune di Prato"); doc.open(); //intestazione par.setAlignment(Paragraph.ALIGN_CENTER); print("Comune di Prato", BOLD15, par, doc); print(titolo, FONT10, par, doc); print("", FONT10, par, doc); //mappa Image mappa = Image.getInstance(uriMappa.toURL()); mappa.setAlignment(Image.MIDDLE); mappa.setBorder(Rectangle.BOX); mappa.setBorderWidth(1f); doc.add(mappa); } catch (Exception e) { logger.error("Errore durante la creazione del PDF", e); printErr(doc); } finally { doc.close(); pdf.close(); response.getOutputStream().close(); } }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
public void save(OutputStream out, ReportBook reportBook) throws SaveReportException { double oldScaleX = GraphicUtil.getScaleX(); double oldScaleY = GraphicUtil.getScaleY(); try {// w w w.j a va 2 s. c om GraphicUtil.setScaleX(1); GraphicUtil.setScaleY(1); ReportPage pageFormat; int i = 0; while (i < reportBook.size() - 1 && !reportBook.getReportModel(i).isVisible()) { i++; } pageFormat = reportBook.getReportModel(i).getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()), Math.round((float) paper.getHeight())); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } Document document = new Document(pageSize, Math.round((float) pageFormat.getLeftMargin(Units.PT)), Math.round((float) pageFormat.getRightMargin(Units.PT)), Math.round((float) pageFormat.getTopMargin(Units.PT)), Math.round((float) pageFormat.getBottomMargin(Units.PT))); try { com.lowagie.text.pdf.PdfWriter.getInstance(document, out); document.addTitle(reportBook.getReportCaption()); document.addCreator("JDBReport using iText"); document.addAuthor(System.getProperty("user.name")); document.open(); int listCount = 0; try { for (ReportModel model : reportBook) { if (model.isVisible()) { listCount = saveSheet(document, listCount, model); } } document.close(); } catch (IOException e) { e.printStackTrace(); } } catch (DocumentException e) { throw new SaveReportException(e); } } finally { GraphicUtil.setScaleX(oldScaleX); GraphicUtil.setScaleY(oldScaleY); } }
From source file:knop.psfj.exporter.PDFSumUpExporter.java
License:Open Source License
/** * Adds the title./* w w w .j a v a 2 s . co m*/ * * @param document * the document */ private void addTitle(Document document) { ReportSections rs = new ReportSections(); try { document.addTitle("PSFj Report"); document.addAuthor("PSFj"); document.add(rs.bigTitle("PSFj Report")); document.add(rs.littleNote(FileUtils.getTodayDate())); } catch (Exception e) { System.err.println("Error when adding title to the report"); e.printStackTrace(); } }