/** * Título del documento. * @param document Documento en cuestión * @throws DocumentException Excepcion generada por algún problema */ private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); addEmptyLine(preface, 1); preface.add(new Paragraph("CitizensLoader PDF", catFont)); // addEmptyLine(preface, 1); // // Will create: Report generated by: _name, _date // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ // smallBold)); // addEmptyLine(preface, 3); // preface.add(new Paragraph("This document describes something which is very important ", smallBold)); // // addEmptyLine(preface, 8); // // preface.add(new Paragraph( // "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", // redFont)); // // document.add(preface); // // Start a new page // document.newPage(); document.add(preface); addEmptyLine(preface, 2); }
private float addImage(PdfPCell cell, String name) { try { java.awt.Image awtImage = (java.awt.Image)iImages.get(name); if (awtImage==null) return 0; Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(ck); } return awtImage.getWidth(null); } catch (Exception e) { return 0; } }
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) { Font font = PdfFont.getFont(bold, italic, underline, color); Chunk chunk = new Chunk(text, font); if (bgColor!=null) chunk.setBackground(bgColor); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(chunk)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(chunk); } float width = 0; if (text.indexOf('\n')>=0) { for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();) width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
public boolean handleCloseGroup() { this.onCloseGroup(); // event handler if(this.rtfParser.isImport()) { if(this.buffer.length()>0) { writeBuffer(); } writeText("}"); } if(this.rtfParser.isConvert()) { if(this.buffer.length() > 0 && this.iTextParagraph == null) { this.iTextParagraph = new Paragraph(); } if(this.buffer.length() > 0 ) { Chunk chunk = new Chunk(); chunk.append(this.buffer.toString()); this.iTextParagraph.add(chunk); } if(this.iTextParagraph != null) { addParagraphToDocument(); } } return true; }
@Test public void writeFile() throws IOException, DocumentException { File file = File.createTempFile("testfile", ".pdf"); File fileWithPageNumbers = File.createTempFile("testfilewithpagenumbers", ".pdf"); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); for(int i = 0; i < 100; i++) { document.add(new Paragraph("Test")); } document.close(); addPageNumbers(file, fileWithPageNumbers.getAbsolutePath()); Assert.assertTrue(file.length() > 0); Assert.assertTrue(fileWithPageNumbers.length() > 0); file.delete(); fileWithPageNumbers.delete(); }
/** * Creates a Paragraph object based on a list of properties. * @param attributes * @return a Paragraph */ public static Paragraph getParagraph(Properties attributes) { Paragraph paragraph = new Paragraph(getPhrase(attributes)); String value; value = attributes.getProperty(ElementTags.ALIGN); if (value != null) { paragraph.setAlignment(value); } value = attributes.getProperty(ElementTags.INDENTATIONLEFT); if (value != null) { paragraph.setIndentationLeft(Float.parseFloat(value + "f")); } value = attributes.getProperty(ElementTags.INDENTATIONRIGHT); if (value != null) { paragraph.setIndentationRight(Float.parseFloat(value + "f")); } return paragraph; }
private static void setParagraphLeading(Paragraph p, String leading) { if (leading == null) { p.setLeading(0, 1.5f); return; } try { StringTokenizer tk = new StringTokenizer(leading, " ,"); String v = tk.nextToken(); float v1 = Float.parseFloat(v); if (!tk.hasMoreTokens()) { p.setLeading(v1, 0); return; } v = tk.nextToken(); float v2 = Float.parseFloat(v); p.setLeading(v1, v2); } catch (Exception e) { p.setLeading(0, 1.5f); } }
/** * Generates a PDF file with the text 'Hello World' * */ @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 System.out (and a txt file) PdfWriter w = PdfWriter.getInstance(document, System.out); w.setCloseStream(false); // System.out should not be closed PdfWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorld.txt")); // step 3: we open the document 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(); }
/** * Generates a PDF file with the text 'Hello World' * */ @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("HelloWorld.pdf")); // step 3: we open the document 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(); }
@Test public void writeSimpeFile () throws IOException, DocumentException { File file = File.createTempFile("testfileVersion", ".pdf"); System.out.println(file.getAbsolutePath()); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); document.add(new Paragraph(Document.getProduct())); document.add(new Paragraph(Document.getVersion())); document.add(new Paragraph(Document.getRelease())); document.close(); System.out.println(Document.getProduct()); System.out.println(Document.getVersion()); System.out.println(Document.getRelease()); }
/** * Creates a PDF document with pages in portrait/landscape. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4.rotate()); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LandscapePortrait.pdf")); // step 3: we open the document document.open(); // step 4: we add some content document.add(new Paragraph( "To create a document in landscape format, just make the height smaller than the width. For instance by rotating the PageSize Rectangle: PageSize.A4.rotate()")); document.setPageSize(PageSize.A4); document.newPage(); document.add(new Paragraph("This is portrait again")); // step 5: we close the document document.close(); }
/** * Generates a PDF file with the text 'Hello World' that is protected with * the password 'Hello'. * */ @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 writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("HelloEncrypted.pdf")); writer.setEncryption("Hello".getBytes(), "World".getBytes(), PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128); // step 3: we open the document 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(); }
/** * 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(); }
/** * Creates a PDF document and shows the iText version. */ @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("version.pdf")); // step 3: we open the document document.open(); // step 4: document.add(new Paragraph("This page was made using " + Document.getVersion())); // step 5: we close the document document.close(); }
/** * Demonstrates the use of PageEvents. */ @Test public void main() throws Exception { Document document = new Document(PageSize.A4, 50, 50, 70, 70); PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("endpage.pdf")); writer.setPageEvent(new EndPageTest()); document.open(); String text = "Lots of text. "; for (int k = 0; k < 10; ++k) text += text; document.add(new Paragraph(text)); document.close(); }
/** * We only alter the handling of some endtags. * * @param uri * the uri of the namespace * @param lname * the local name of the tag * @param name * the name of the tag */ public void endElement(String uri, String lname, String name) { if (myTags.containsKey(name)) { XmlPeer peer = (XmlPeer) myTags.get(name); // we don't want the document to be close // because we are going to add a page after the xml is parsed if (isDocumentRoot(peer.getTag())) { return; } handleEndingTags(peer.getTag()); // we want to add a paragraph after the speaker chunk if ("SPEAKER".equals(name)) { try { TextElementArray previous = (TextElementArray) stack .pop(); previous.add(new Paragraph(16)); stack.push(previous); } catch (EmptyStackException ese) { } } } else { handleEndingTags(name); } }
/** * Changing the width of font glyphs. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fixedfontwidth.pdf")); // step 3 document.open(); // step 4 BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null); int widths[] = bf.getWidths(); for (int k = 0; k < widths.length; ++k) { if (widths[k] != 0) widths[k] = 1000; } bf.setForceWidthsOutput(true); document.add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf))); // step 5 document.close(); }
/** * Use of paragraph stylesheets. * * */ @Test public void main() throws Exception { Document document = new Document(); RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("BasicStylesheets.rtf")); document.open(); // Simply set the stylesheet you wish to use as the Font // of the Paragraph document.add(new Paragraph("This is a heading", RtfParagraphStyle.STYLE_HEADING_1)); document.add(new Paragraph("Just some text that is formatted " + "in the default style.", RtfParagraphStyle.STYLE_NORMAL)); document.close(); }
/** * Using oth */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2 PdfWriter.getInstance(document, PdfTestBase.getOutputStream("opentypefont.pdf")); // step 3 document.open(); // step 4 BaseFont bf = BaseFont.createFont(PdfTestBase.RESOURCES_DIR + "liz.otf", BaseFont.CP1252, true); String text = "Some text with the otf font LIZ."; document.add(new Paragraph(text, new Font(bf, 14))); // step 5 document.close(); }
/** * Generates an Acroform with a Signature */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("signature.pdf")); // step 3: we open the document document.open(); // step 4: PdfAcroForm acroForm = writer.getAcroForm(); document.add(new Paragraph("Hello World")); acroForm.addSignature("mysig", 73, 705, 149, 759); // step 5: we close the document document.close(); }
/** * Creates a document with a javascript action. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.pdf")); // step 3: we add Javascript as Metadata and we open the document document.open(); // step 4: we add some content Paragraph p = new Paragraph(new Chunk("Click to say Hello").setAction(PdfAction.javaScript( "app.alert('Hello');\r", writer))); document.add(p); // step 5: we close the document document.close(); }
/** * Creates a document with Named Actions. * * @param args The file to open */ public void main(String... args) throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2: we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OpenApplication.pdf")); // step 3: we open the document document.open(); // step 4: we add some content String application = args[0]; Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction( new PdfAction(application, null, null, null))); document.add(p); // step 5: we close the document document.close(); }
/** * Creates a document with chained Actions. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ChainedActions.pdf")); // step 3: we add Javascript as Metadata and we open the document document.open(); // step 4: we add some content PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer); action.next(new PdfAction("http://www.lowagie.com/iText/")); Paragraph p = new Paragraph(new Chunk("Click to go to Bruno's site").setAction(action)); document.add(p); // step 5: we close the document document.close(); }
/** * Using FontSelector. */ @Test public void main() throws Exception { // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document, PdfTestBase.getOutputStream("differentfonts.pdf")); // step 3 document.open(); // step 4 Paragraph p = new Paragraph(); p.add(new Chunk("This text is in Times Roman. This is ZapfDingbats: ", new Font(Font.TIMES_ROMAN, 12))); p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.ZAPFDINGBATS, 12))); p.add(new Chunk(". This is font Symbol: ", new Font(Font.TIMES_ROMAN, 12))); p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.SYMBOL, 12))); document.add(new Paragraph(p)); // step 5 document.close(); }
/** * Generates an HTML page with the text 'Hello World' * */ @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 HTML-stream to a file HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorld.html")); // step 3: we open the document 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(); }
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading, float padding, Rectangle borders, boolean ascender, boolean descender) { Paragraph p = new Paragraph(text, font); p.setLeading(leading); PdfPCell cell = new PdfPCell(p); cell.setLeading(leading, 0); cell.setVerticalAlignment(vAlignment); cell.setHorizontalAlignment(hAlignment); cell.cloneNonPositionParameters(borders); cell.setUseAscender(ascender); cell.setUseDescender(descender); cell.setUseBorderPadding(true); cell.setPadding(padding); return cell; }
/** * A very simple Table example. * */ @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("MyFirstTable.pdf")); // step 3: we open the document document.open(); // step 4: we create a table and add it to the document Table table = new Table(2, 2); // 2 rows, 2 columns table.addCell("0.0"); table.addCell("0.1"); table.addCell("1.0"); table.addCell("1.1"); document.add(table); document.add(new Paragraph("converted to PdfPTable:")); table.setConvert2pdfptable(true); document.add(table); // step 5: we close the document document.close(); }
/** * Hello World! example * */ @Test public void main() throws Exception { // Step 1: Create a new Document Document document = new Document(); // Step 2: Create a new instance of the RtfWriter2 with the document // and target output stream. RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("HelloWorld.rtf")); // Step 3: Open the document. document.open(); // Step 4: Add content to the document. document.add(new Paragraph("Hello World!")); // Step 5: Close the document. It will be written to the target output // stream. document.close(); }
public void createContent(WebInput wi, DocInfo di)throws ControllerException { Document pdfDoc = di.getPdfDocument(); try { pdfDoc.add(new Paragraph("Hello World!")); try { BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font FontChinese = new Font(bf, 12, Font.NORMAL); String info=wi.getParameter("info"); Paragraph p0 = new Paragraph(info, FontChinese); pdfDoc.add(p0); Paragraph p1 = new Paragraph("Beetle Web Framework 页面生成PDF文件演示!", FontChinese); pdfDoc.add(p1); } catch (Exception ex1) { throw new ControllerException(ex1); } } catch (DocumentException ex) { throw new ControllerException(ex); } }
private Paragraph generateContent(Grade grade) throws BadElementException { Paragraph content = new Paragraph(); Table table = createTable(grade); content.add(table); return content; }
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(text, PdfFont.getSmallFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getSmallFont(bold))); } }
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); Font font = PdfFont.getFont(bold); BaseFont bf = font.getBaseFont(); float width = bf.getWidthPoint(text, font.getSize()); PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width); template.beginText(); template.setColorFill(Color.BLACK); template.setFontAndSize(bf, font.getSize()); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(font.getSize() + 2); //make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(270); //embed the image in a Chunk Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.getPhrase().add(ck); } }
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; if (text.indexOf("<span")>=0) text = text.replaceAll("</span>","").replaceAll("<span .*>", ""); text = text.replaceAll("<br>", "\n"); text = text.replaceAll("<BR>", "\n"); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getFont(bold))); } }
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text==null) return; if (cell.getPhrase()==null) { Chunk ch = new Chunk(text, PdfFont.getFont(bold, italic, color)); cell.setPhrase(new Paragraph(ch)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(orientation); } else { cell.getPhrase().add(new Chunk((newLine?"\n":"")+text, PdfFont.getFont(bold, italic, color))); } }
protected void printFooter() throws DocumentException { iEmpty=false; out(""); out(renderEnd(renderMiddle((iFooter==null?"":iFooter),"Page "+(iPageNo+1)),(iPageId==null||iPageId.length()==0?"":iPageId)+" ")); if (iPrint!=null) { iPrint.print(iBuffer); } else { //FIXME: For some reason when a line starts with space, the line is shifted by one space in the resulting PDF (when using iText 5.0.2) Paragraph p = new Paragraph(iBuffer.toString().replace("\n ", "\n "), PdfFont.getFixedFont()); p.setLeading(9.5f); //was 13.5f iDoc.add(p); } iBuffer = new StringBuffer(); iPageNo++; }
protected void printFooter() throws DocumentException { out(""); out(renderEnd(renderMiddle("","Page "+(iPageNo+1)),"<"+iCurrentSubjectArea.getSubjectAreaAbbreviation()+(iCourseNumber!=null?" "+iCourseNumber:"")+"> ")); //FIXME: For some reason when a line starts with space, the line is shifted by one space in the resulting PDF (when using iText 5.0.2) Paragraph p = new Paragraph(iBuffer.toString().replace("\n ", "\n "), PdfFont.getFixedFont()); p.setLeading(9.5f); //was 13.5f iDoc.add(p); iBuffer = new StringBuffer(); iPageNo++; }
@Override public void printHeader(String... fields) { iTable = new PdfPTable(fields.length - iHiddenColumns.size()); iMaxWidth = new float[fields.length]; iTable.setHeaderRows(1); iTable.setWidthPercentage(100); for (int idx = 0; idx < fields.length; idx++) { if (iHiddenColumns.contains(idx)) continue; String f = fields[idx]; PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); Font font = PdfFont.getFont(true); Paragraph ch = new Paragraph(f, font); ch.setLeading(0f, 1f); cell.addElement(ch); iTable.addCell(cell); float width = 0; if (f.indexOf('\n')>=0) { for (StringTokenizer s = new StringTokenizer(f,"\n"); s.hasMoreTokens();) width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width,font.getBaseFont().getWidthPoint(f, font.getSize())); iMaxWidth[idx] = width; } }
/** * 功能说明:设置段落的样式,设置前半截内容和后半截内容格式不一样的段落样式</BR> * 修改日:2011-04-27 * @author myclover * @param content 前半截内容 * @param font 字体的样式 * @param firstLineIndent 首行缩进多少字符,16f约等于一个字符 * @param appendStr 后半截内容 * @return */ public static Paragraph setParagraphStyle(String content , Font font , float firstLineIndent , String appendStr){ Paragraph par = setParagraphStyle(content, font, 0f, 12f); Phrase phrase = new Phrase(); phrase.add(par); phrase.add(appendStr); Paragraph paragraph = new Paragraph(phrase); paragraph.setFirstLineIndent(firstLineIndent); //设置对齐方式为两端对齐 paragraph.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL); return paragraph; }
@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(); }
@Test public void testBasicDocument() throws Exception { initializeDocument(); writer.getDirectContent().saveState(); document.add(new Paragraph("Hello World")); writer.getDirectContent().restoreState(); document.close(); }