Java Code Examples for com.lowagie.text.Document#addAuthor()
The following examples show how to use
com.lowagie.text.Document#addAuthor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloWorldMetaTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Generates a PDF file with metadata * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorldMeta.pdf")); // step 3: we add some metadata open the document document.addTitle("Hello World example"); document.addSubject("This example explains how to add metadata."); document.addKeywords("iText, Hello World, step 3, metadata"); document.addCreator("My program using iText"); document.addAuthor("Bruno Lowagie"); document.open(); // step 4: we add a paragraph to the document document.add(new Paragraph("Hello World")); // step 5: we close the document document.close(); }
Example 2
Source File: PdfDocumentFactory.java From javamelody with Apache License 2.0 | 6 votes |
Document createDocument(boolean landscape) throws DocumentException, IOException { // creation of a document-object final Rectangle pageSize = getPageSize(landscape); // marges de 20 à gauche, à droite et en haut pour bien utiliser la largeur // et avoir une meilleur lisibilité sur les tableaux larges, // mais marge de 40 en bas pour ne pas empiéter sur les numéros de pages final Document document = new Document(pageSize, 20, 20, 20, 40); final String title; if (range == null) { title = I18N.getFormattedString("Monitoring_sur", application); } else { title = I18N.getFormattedString("Monitoring_sur", application) + " - " + range.getLabel(); } createWriter(document, title); // we add some meta information to the document (after writer) document.addAuthor(application); document.addCreator( "JavaMelody par E. Vernat, https://github.com/javamelody/javamelody/wiki"); document.addTitle(title); return document; }
Example 3
Source File: PdfLegacyReport.java From unitime with Apache License 2.0 | 6 votes |
public void open(OutputStream out, int mode) throws DocumentException, IOException { iOut = out; if (mode==sModeText) { iPrint = new PrintWriter(iOut); } else { iNrLines = (mode==sModeLedger?116:50); iDoc = new Document(mode==sModeLedger?PageSize.LEDGER.rotate():PageSize.LETTER.rotate()); PdfWriter.getInstance(iDoc, iOut); iDoc.addTitle(iTitle); iDoc.addAuthor("UniTime "+Constants.getVersion()+", www.unitime.org"); iDoc.addSubject(iSubject); iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org"); iDoc.open(); } iEmpty = true; iPageNo = 0; iLineNo = 0; }
Example 4
Source File: HelloWorldMetaTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates a PDF file with metadata * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorldMeta.html")); // step 3: we add some metadata open the document // standard meta information document.addTitle("Hello World example"); document.addAuthor("Bruno Lowagie"); document.addSubject("This example explains step 3 in Chapter 1"); document.addKeywords("Metadata, iText, step 3, tutorial"); // custom (HTML) meta information document.addHeader("Expires", "0"); // meta information that will be in a comment section in HTML document.addCreator("My program using iText"); document.open(); // step 4: we add a paragraph to the document document.add(new Paragraph("Hello World")); // step 5: we close the document document.close(); }
Example 5
Source File: MetaDataTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testAddedMetadata() throws Exception { String AUTHOR_NAME = "Mr Bean"; String TITLE = "The title"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, baos); document.open(); document.addProducer(); document.addAuthor(AUTHOR_NAME); document.addTitle(TITLE); document.add(new Paragraph("Hello World")); document.close(); PdfReader r = new PdfReader(baos.toByteArray()); // Metadata generated only on demand Assert.assertEquals(Document.getVersion(), r.getInfo().get("Producer")); Assert.assertEquals(AUTHOR_NAME, r.getInfo().get("Author")); Assert.assertEquals(TITLE, r.getInfo().get("Title")); r.close(); }
Example 6
Source File: PdfWorksheet.java From unitime with Apache License 2.0 | 5 votes |
private PdfWorksheet(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber) throws IOException, DocumentException { iUseCommitedAssignments = ApplicationProperty.WorksheetPdfUseCommittedAssignments.isTrue(); iSubjectAreas = new TreeSet<SubjectArea>(new Comparator<SubjectArea>() { @Override public int compare(SubjectArea s1, SubjectArea s2) { return s1.getSubjectAreaAbbreviation().compareTo(s2.getSubjectAreaAbbreviation()); } }); iSubjectAreas.addAll(subjectAreas); iCourseNumber = courseNumber; if (iCourseNumber!=null && (iCourseNumber.trim().length()==0 || "*".equals(iCourseNumber.trim().length()))) iCourseNumber = null; iDoc = new Document(PageSize.LETTER.rotate()); iOut = out; PdfWriter.getInstance(iDoc, iOut); String session = null; String subjects = ""; for (SubjectArea sa: iSubjectAreas) { if (subjects.isEmpty()) subjects += ", "; subjects += sa.getSubjectAreaAbbreviation(); if (session == null) session += sa.getSession().getLabel(); } iDoc.addTitle(subjects + (iCourseNumber==null?"":" "+iCourseNumber) + " Worksheet"); iDoc.addAuthor(ApplicationProperty.WorksheetPdfAuthor.value().replace("%", Constants.getVersion())); iDoc.addSubject(subjects + (session == null ? "" : " -- " + session)); iDoc.addCreator("UniTime "+Constants.getVersion()+", www.unitime.org"); if (!iSubjectAreas.isEmpty()) iCurrentSubjectArea = iSubjectAreas.first(); iDoc.open(); printHeader(); }
Example 7
Source File: RepeatingTableTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Shows how a table is split if it doesn't fit the page. */ @Test public void main() throws Exception { // creation of the document with a certain size and certain margins Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); // creation of the different writers PdfWriter.getInstance(document, PdfTestBase.getOutputStream("repeatingtable.pdf")); // we add some meta information to the document document.addAuthor("Alan Soukup"); document.addSubject("This is the result of a Test."); document.open(); Table datatable = new Table(10); int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 }; datatable.setWidths(headerwidths); datatable.setWidth(100); datatable.setPadding(3); // the first cell spans 10 columns Cell cell = new Cell(new Phrase("Administration -System Users Report", FontFactory.getFont( FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setLeading(30); cell.setColspan(10); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); datatable.addCell(cell); // These cells span 2 rows datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(1); datatable.addCell("User Id"); datatable.addCell("Name\nAddress"); datatable.addCell("Company"); datatable.addCell("Department"); datatable.addCell("Admin"); datatable.addCell("Data"); datatable.addCell("Expl"); datatable.addCell("Prod"); datatable.addCell("Proj"); datatable.addCell("Online"); // this is the end of the table header datatable.endHeaders(); datatable.getDefaultCell().setBorderWidth(1); for (int i = 1; i < 30; i++) { datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("myUserId"); datatable .addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name"); datatable.addCell("No Name Company"); datatable.addCell("D" + i); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); datatable.addCell("No"); datatable.addCell("Yes"); } document.add(new Paragraph("com.lowagie.text.Table - Cells split")); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells split\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.Table - Cells kept together")); datatable.setConvert2pdfptable(false); datatable.setCellsFitPage(true); document.add(datatable); document.newPage(); document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells kept together\n\n")); datatable.setConvert2pdfptable(true); document.add(datatable); // we close the document document.close(); }
Example 8
Source File: VisualizePanelCharts2D.java From KEEL with GNU General Public License v3.0 | 4 votes |
private void topdfjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_topdfjButtonActionPerformed // Save chart as a PDF file JFileChooser chooser = new JFileChooser(); chooser.setDialogTitle("Save chart"); KeelFileFilter fileFilter = new KeelFileFilter(); fileFilter.addExtension("pdf"); fileFilter.setFilterName("PDF images (.pdf)"); chooser.setFileFilter(fileFilter); chooser.setCurrentDirectory(Path.getFilePath()); int opcion = chooser.showSaveDialog(this); Path.setFilePath(chooser.getCurrentDirectory()); if (opcion == JFileChooser.APPROVE_OPTION) { String nombre = chooser.getSelectedFile().getAbsolutePath(); if (!nombre.toLowerCase().endsWith(".pdf")) { // Add correct extension nombre += ".pdf"; } File tmp = new File(nombre); if (!tmp.exists() || JOptionPane.showConfirmDialog(this, "File " + nombre + " already exists. Do you want to replace it?", "Confirm", JOptionPane.YES_NO_OPTION, 3) == JOptionPane.YES_OPTION) { try { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nombre)); document.addAuthor("KEEL"); document.addSubject("Attribute comparison"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(550, 412); Graphics2D g2 = tp.createGraphics(550, 412, new DefaultFontMapper()); Rectangle2D r2D = new Rectangle2D.Double(0, 0, 550, 412); chart2.setBackgroundPaint(Color.white); chart2.draw(g2, r2D); g2.dispose(); cb.addTemplate(tp, 20, 350); document.close(); } catch (Exception exc) { } } } }
Example 9
Source File: MPdfWriter.java From javamelody with Apache License 2.0 | 4 votes |
/** * Ecrit le pdf. * * @param table * MBasicTable * @param out * OutputStream * @throws IOException * e */ protected void writePdf(final MBasicTable table, final OutputStream out) throws IOException { try { // step 1: creation of a document-object final Rectangle pageSize = landscape ? PageSize.A4.rotate() : PageSize.A4; final Document document = new Document(pageSize, 50, 50, 50, 50); // step 2: we create a writer that listens to the document and directs a PDF-stream to out createWriter(table, document, out); // we add some meta information to the document, and we open it document.addAuthor(System.getProperty("user.name")); document.addCreator("JavaMelody"); final String title = buildTitle(table); if (title != null) { document.addTitle(title); } document.open(); // ouvre la boîte de dialogue Imprimer de Adobe Reader // if (writer instanceof PdfWriter) { // ((PdfWriter) writer).addJavaScript("this.print(true);", false); // } // table final Table datatable = new Table(table.getColumnCount()); datatable.setCellsFitPage(true); datatable.setPadding(4); datatable.setSpacing(0); // headers renderHeaders(table, datatable); // data rows renderList(table, datatable); document.add(datatable); // we close the document document.close(); } catch (final DocumentException e) { // on ne peut déclarer d'exception autre que IOException en throws throw new IOException(e); } }