Java Code Examples for com.lowagie.text.Document#addTitle()
The following examples show how to use
com.lowagie.text.Document#addTitle() .
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: MPdfWriter.java From javamelody with Apache License 2.0 | 6 votes |
/** * We create a writer that listens to the document and directs a PDF-stream to out * * @param table * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter * @throws DocumentException * e */ protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) throws DocumentException { final PdfWriter writer = PdfWriter.getInstance(document, out); // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title if (table.getName() != null) { final HeaderFooter header = new HeaderFooter(new Phrase(table.getName()), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(table.getName()); } // simple page numbers : x // HeaderFooter footer = new HeaderFooter(new Phrase(), true); // footer.setAlignment(Element.ALIGN_RIGHT); // footer.setBorder(Rectangle.TOP); // document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new AdvancedPageNumberEvents()); return writer; }
Example 4
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 5
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 6
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 7
Source File: MRtfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter */ @Override protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) { final RtfWriter2 writer = RtfWriter2.getInstance(document, out); // title final String title = buildTitle(table); if (title != null) { final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title)); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } // advanced page numbers : x/y final Paragraph footerParagraph = new Paragraph(); final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); footerParagraph.add(new RtfPageNumber(font)); footerParagraph.add(new Phrase(" / ", font)); footerParagraph.add(new RtfTotalPageNumber(font)); footerParagraph.setAlignment(Element.ALIGN_CENTER); final HeaderFooter footer = new RtfHeaderFooter(footerParagraph); footer.setBorder(Rectangle.TOP); document.setFooter(footer); return writer; }
Example 8
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 9
Source File: ViewerPreferencesTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Creates documents with different viewerpreferences. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A6); // step 2: PdfWriter writer1 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("TwoColumnLeft.pdf")); PdfWriter writer2 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("HideMenuToolbar.pdf")); PdfWriter writer3 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("FullScreen.pdf")); PdfWriter writer4 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("WithTitle.pdf")); PdfWriter writer5 = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NoScaling.pdf")); // step 3: writer1.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); writer2.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideMenubar); writer3.setViewerPreferences(PdfWriter.PageLayoutTwoColumnRight | PdfWriter.PageModeFullScreen | PdfWriter.NonFullScreenPageModeUseThumbs); writer4.setViewerPreferences(PdfWriter.DisplayDocTitle); writer5.setViewerPreferences(PdfWriter.PrintScalingNone); document.addTitle("Julius Caesar"); document.open(); // step 4: we grab the ContentByte and do some stuff with it document.add(new Paragraph( "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.", new Font(Font.HELVETICA, 12))); document.add(new Paragraph( "Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", new Font(Font.HELVETICA, 12))); // step 5: we close the document document.close(); }
Example 10
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); } }