List of usage examples for com.itextpdf.text Document addAuthor
public boolean addAuthor(String author)
From source file:Modelo.RelatoriosBEAN.java
public static void notaDeCompra(NotaDecompraBEAN n) throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();//from w w w .ja v a 2 s . c o m document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de Jogos Comprados </h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo</strong></th> " + "<th align=center><strong>Custo Unitrio</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor da Entrada</strong></th> " + "<th align=center><strong>Nmero de parcelas</strong></th> " + "<th align=center><strong>Preo Total</strong></th> " + "<th align=center><strong>Quantidade Compradra</strong></th> " + "<th align=center><strong>Caixa</strong></th> " + "<th align=center><strong>Jogo</strong></th> " + "</tr> "; frase += "<tr align=center><td>" + n.getNdcCodigo() + "</td><td>" + n.getNdcCustoUnitario() + "</td><td>" + n.getNdcData() + "</td><td>" + n.getNdcEntrada() + "</td><td>" + n.getNdcParcelas() + "</td><td>" + n.getNdcPrecoTotal() + "</td><td>" + n.getNdcQtdComprada() + "</td><td>" + n.getCaixa().getCaixaCodigo() + "</td><td>" + n.getJogo().getJoNome() + "</td></tr>" + "</table>"; ; frase += "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<br/><br/>" + "<tr> " + "<th align=center><strong>Parcela</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor</strong></th> " + "<th align=center><strong>Situao</strong></th> " + "</tr> "; for (NotaDeCompraPrazoBEAN nap : cNdcap.listarALL()) { if (nap.getNota().getNdcCodigo() == n.getNdcCodigo()) { frase += "<tr align=center><td>" + nap.getNapNumParcela() + "</td><td>" + nap.getNapData() + "</td><td>" + nap.getNapValor() + "</td><td>" + nap.getNapSituacao() + "</td></tr>"; } } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:negotiation.Contract.FormContractPdf.java
public static void addMetaData(Document document) { document.addTitle("FitSM Module"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText, FitSM"); document.addAuthor("Zeqian Meng"); document.addCreator("Zeqian Meng"); }
From source file:net.FilterLogic.imaging.ToPDF.java
License:Apache License
/** * Iterate through properties and set each value for PDF document. */// w w w . j a va 2 s.co m private void setDocumentProperties(Document pdf) { for (Enumeration e = this.documentProperties.keys(); e.hasMoreElements();) { String name = e.nextElement().toString().toUpperCase(); String value = this.documentProperties.getProperty(name); if (name.equals("TITLE")) pdf.addTitle(value); if (name.equals("AUTHOR")) pdf.addAuthor(value); // if(name.equals("CREATOR")) // pdf.addCreator(value); if (name.equals("CREATIONDATE")) pdf.addCreationDate(); if (name.equals("SUBJECT")) pdf.addSubject(value); if (name.equals("KEYWORDS")) pdf.addKeywords(value); } }
From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java
License:Apache License
/** * Creates a PDF document./*from w w w . j a va 2 s. c om*/ * @param bean a generation bean (not null) * @throws DocumentException * @throws FileNotFoundException */ public void createDocument(GenerationDataBean bean) throws FileNotFoundException, DocumentException { // Create the document File outputFile = new File("./Feuille-De-Temps.pdf"); final Document doc = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(doc, new FileOutputStream(outputFile)); doc.open(); doc.addAuthor(bean.getName()); doc.addCreator(bean.getName()); String s; if (bean.getEndWeek() - bean.getStartWeek() > 1) s = "Feuilles de Temps - Semaines " + bean.getStartWeek() + " " + bean.getEndWeek(); else s = "Feuille de Temps - Semaine " + bean.getStartWeek(); doc.addTitle(s); doc.addSubject(s); // Add pages for (int i = bean.getStartWeek(); i <= bean.getEndWeek(); i++) addPageForWeek(i, doc, bean); // That's it! doc.close(); }
From source file:nz.ac.waikato.cms.doc.OverlayFilename.java
License:Open Source License
/** * Performs the overlay./* www.j av a 2s. c o m*/ * * @param input the input file/dir * @param output the output file/dir * @param vpos the vertical position * @param hpos the horizontal position * @param stripPath whether to strip the path * @param stripExt whether to strip the extension * @param pages the array of pages (1-based) to add the overlay to, null for all * @param evenPages whether to enforce even pages in the document * @return true if successfully overlay */ public boolean overlay(File input, File output, int vpos, int hpos, boolean stripPath, boolean stripExt, int[] pages, boolean evenPages) { PdfReader reader; PdfStamper stamper; FileOutputStream fos; PdfContentByte canvas; int i; String text; int numPages; File tmpFile; Document document; PdfWriter writer; PdfImportedPage page; PdfContentByte cb; reader = null; stamper = null; fos = null; numPages = -1; try { reader = new PdfReader(input.getAbsolutePath()); fos = new FileOutputStream(output.getAbsolutePath()); stamper = new PdfStamper(reader, fos); numPages = reader.getNumberOfPages(); if (pages == null) { pages = new int[reader.getNumberOfPages()]; for (i = 0; i < pages.length; i++) pages[i] = i + 1; } if (stripPath) text = input.getName(); else text = input.getAbsolutePath(); if (stripExt) text = text.replaceFirst("\\.[pP][dD][fF]$", ""); for (i = 0; i < pages.length; i++) { canvas = stamper.getOverContent(pages[i]); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Paragraph(text), hpos, vpos, 0.0f); } } catch (Exception e) { System.err.println("Failed to process " + input + ":"); e.printStackTrace(); return false; } finally { try { if (stamper != null) stamper.close(); } catch (Exception e) { // ignored } try { if (reader != null) reader.close(); } catch (Exception e) { // ignored } try { if (fos != null) { fos.flush(); fos.close(); } } catch (Exception e) { // ignored } } // enforce even pages? if (evenPages && (numPages > 0) && (numPages % 2 == 1)) { reader = null; fos = null; writer = null; tmpFile = new File(output.getAbsolutePath() + "tmp"); try { if (!output.renameTo(tmpFile)) { System.err.println("Failed to rename '" + output + "' to '" + tmpFile + "'!"); return false; } reader = new PdfReader(tmpFile.getAbsolutePath()); document = new Document(reader.getPageSize(1)); fos = new FileOutputStream(output.getAbsoluteFile()); writer = PdfWriter.getInstance(document, fos); document.open(); document.addCreationDate(); document.addAuthor(System.getProperty("user.name")); cb = writer.getDirectContent(); for (i = 0; i < reader.getNumberOfPages(); i++) { page = writer.getImportedPage(reader, i + 1); document.newPage(); cb.addTemplate(page, 0, 0); } document.newPage(); document.add(new Paragraph(" ")); // fake content document.close(); } catch (Exception e) { System.err.println("Failed to process " + tmpFile + ":"); e.printStackTrace(); return false; } finally { try { if (fos != null) { fos.flush(); fos.close(); } } catch (Exception e) { // ignored } try { if (reader != null) reader.close(); } catch (Exception e) { // ignored } try { if (writer != null) writer.close(); } catch (Exception e) { // ignored } if (tmpFile.exists()) { try { tmpFile.delete(); } catch (Exception e) { // ignored } } } } return true; }
From source file:org.bonitasoft.studio.migration.utils.PDFMigrationReportWriter.java
License:Open Source License
private void addMetaData(Document document) { document.addTitle(report.getName()); document.addSubject("Migration status report"); document.addKeywords("BPMN, Migration, BonitaSoft, Process"); document.addAuthor("Bonita Studio"); document.addCreator("Bonita Studio"); }
From source file:org.cidte.sii.negocio.PDFWriter.java
public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image) throws DocumentException, FileNotFoundException, BadElementException, IOException { Document doc = new Document(); PdfWriter docWriter;/*from w ww . j a va 2 s. c o m*/ // special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); // file path String path = directorio + nombre + ".pdf"; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path))); // document header attributes doc.addAuthor("sii"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("sii"); doc.addTitle(nombre); doc.setPageSize(PageSize.LETTER); // open document doc.open(); Image img = Image.getInstance(image, null); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); // create a paragraph Paragraph paragraph = new Paragraph("iText is a library that allows you to create and " + "manipulate PDF documents. It enables developers looking to enhance web and other " + "applications with dynamic PDF document generation and/or manipulation."); // create PDF table with the given widths PdfPTable table = new PdfPTable(list.get(0).getNames().length); // set table width a percentage of the page width table.setWidthPercentage(100); table.setSpacingBefore(10f); // Space before table table.setSpacingAfter(10f); // Space after table // insert column headings String[] headings = list.get(0).getNames(); for (String heading : headings) { insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); // insert the data for (int i = 0; i < list.size(); i++) { Writable w = list.get(i); Object[] arr = w.getAsArray(); for (int j = 0; j < arr.length; j++) { // arr[j] insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12); } } // insert an empty row // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12); // add the PDF table to the paragraph paragraph.add(table); // add the paragraph to the document doc.add(paragraph); // close the document doc.close(); // close the writer docWriter.close(); }
From source file:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java
License:Open Source License
/** * @param mainFileUrl//ww w. j a v a 2 s. co m * : PDF file that has to be splitted * @param splittedPageSize * : Page size of each splitted files */ private static String splitAndSaveChapter(String mainFileUrl, int pageBeginNum, int pageEndNum, String name) { try { PdfReader reader = new PdfReader(mainFileUrl); int splittedPageSize = pageEndNum - pageBeginNum + 1; int pageNum = pageBeginNum; String chapterUrl = mainFileUrl.substring(0, mainFileUrl.indexOf(DOT_PDF)) + "-" + name + DOT_PDF; Document document = new Document(reader.getPageSizeWithRotation(1)); FileOutputStream fos = new FileOutputStream(chapterUrl); PdfCopy writer = new PdfCopy(document, fos); Map<String, String> info = reader.getInfo(); document.open(); if ((info != null) && (info.get(_AUTHOR) != null)) { document.addAuthor(info.get(_AUTHOR)); } document.addTitle(name); for (int offset = 0; offset < splittedPageSize && (pageNum + offset) < pageEndNum; offset++) { PdfImportedPage page = writer.getImportedPage(reader, pageNum + offset); writer.addPage(page); } document.close(); writer.close(); return chapterUrl; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.fhaes.fhsamplesize.view.SSIZCurveChart.java
License:Open Source License
/** * Save chart as PDF file. Requires iText library. * // w ww .j a va 2s.c o m * @param chart JFreeChart to save. * @param fileName Name of file to save chart in. * @param width Width of chart graphic. * @param height Height of chart graphic. * @throws Exception if failed. * @see <a href="http://www.lowagie.com/iText">iText</a> */ @SuppressWarnings("deprecation") public static void writeAsPDF(File fileToSave, int width, int height) throws Exception { if (chart != null) { BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(fileToSave.getAbsolutePath())); // convert chart to PDF with iText: Rectangle pagesize = new Rectangle(width, height); Document document = new Document(pagesize, 50, 50, 50, 50); try { PdfWriter writer = PdfWriter.getInstance(document, out); document.addAuthor("JFreeChart"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, r2D, null); g2.dispose(); cb.addTemplate(tp, 0, 0); } finally { document.close(); } } finally { if (out != null) out.close(); } } }
From source file:org.gbif.ipt.task.Eml2Pdf.java
/** * Construct PDF document, mainly out of information extracted from Resource's EML object. */*from w w w . j av a2 s . com*/ * @param doc Document * @param resource Resource * @param lng language of the document * * @throws DocumentException if problem occurs during add */ private void addMetaData(Document document) { log.info("Adding metadata info to document"); document.addTitle(getText("pdf.title.doc")); document.addSubject(getText("pdf.subj.doc")); document.addAuthor(getText("pdf.author.doc")); document.addCreator(getText("pdf.creator.doc")); }