Chunk implements Element, IAccessibleElement { public Font getFont() { return font; } Chunk();  Chunk(final Chunk ck);  Chunk(final String content, final Font font);  Chunk(final String content);  Chunk(final char c, final Font font);  Chunk(final char c);  Chunk(final Image image, final float offsetX, final float offsetY);  Chunk(final DrawInterface separator);  Chunk(final DrawInterface separator, final boolean vertical); @Deprecated  Chunk(final DrawInterface separator, final float tabPosition); @Deprecated  Chunk(final DrawInterface separator, final float tabPosition, final boolean newline); private  Chunk(final Float tabInterval, final boolean isWhitespace);  Chunk(final Image image, final float offsetX, final float offsetY,
			final boolean changeLeading); boolean process(final ElementListener listener); int type(); List<Chunk> getChunks(); StringBuffer append(final String string); void setFont(final Font font); Font getFont(); String getContent(); @Override String toString(); boolean isEmpty(); float getWidthPoint(); boolean hasAttributes(); boolean hasAccessibleAttributes(); HashMap<String, Object> getAttributes(); void setAttributes(final HashMap<String, Object> attributes); Chunk setHorizontalScaling(final float scale); float getHorizontalScaling(); Chunk setUnderline(final float thickness, final float yPosition); Chunk setUnderline(final BaseColor color, final float thickness, final float thicknessMul,
			final float yPosition, final float yPositionMul, final int cap); Chunk setTextRise(final float rise); float getTextRise(); Chunk setSkew(float alpha, float beta); Chunk setBackground(final BaseColor color); Chunk setBackground(final BaseColor color, final float extraLeft, final float extraBottom,
			final float extraRight, final float extraTop); Chunk setTextRenderMode(final int mode, final float strokeWidth,
			final BaseColor strokeColor); Chunk setSplitCharacter(final SplitCharacter splitCharacter); Chunk setHyphenation(final HyphenationEvent hyphenation); Chunk setRemoteGoto(final String filename, final String name); Chunk setRemoteGoto(final String filename, final int page); Chunk setLocalGoto(final String name); Chunk setLocalDestination(final String name); Chunk setGenericTag(final String text); Chunk setLineHeight(float lineheight); Image getImage(); Chunk setAction(final PdfAction action); Chunk setAnchor(final URL url); Chunk setAnchor(final String url); Chunk setNewPage(); Chunk setAnnotation(final PdfAnnotation annotation); boolean isContent(); boolean isNestable(); HyphenationEvent getHyphenation(); Chunk setCharacterSpacing(final float charSpace); float getCharacterSpacing(); Chunk setWordSpacing(final float wordSpace); float getWordSpacing(); static Chunk createWhitespace(final String content); static Chunk createWhitespace(final String content, final boolean preserve); boolean isWhitespace(); @Deprecated static Chunk createTabspace(); @Deprecated static Chunk createTabspace(float spacing); @Deprecated boolean isTabspace(); PdfObject getAccessibleAttribute(final PdfName key); void setAccessibleAttribute(final PdfName key, final PdfObject value); HashMap<PdfName, PdfObject> getAccessibleAttributes(); PdfName getRole(); void setRole(final PdfName role); AccessibleElementId getId(); void setId(final AccessibleElementId id); boolean isInline(); String getTextExpansion(); void setTextExpansion(String value); static final String OBJECT_REPLACEMENT_CHARACTER; static final Chunk NEWLINE; static final Chunk NEXTPAGE; static final Chunk TABBING; static final Chunk SPACETABBING; static final String SEPARATOR; static final String TAB; static final String TABSETTINGS; static final String HSCALE; static final String UNDERLINE; static final String SUBSUPSCRIPT; static final String SKEW; static final String BACKGROUND; static final String TEXTRENDERMODE; static final String SPLITCHARACTER; static final String HYPHENATION; static final String REMOTEGOTO; static final String LOCALGOTO; static final String LOCALDESTINATION; static final String GENERICTAG; static final String LINEHEIGHT; static final String IMAGE; static final String ACTION; static final String NEWPAGE; static final String PDFANNOTATION; static final String COLOR; static final String ENCODING; static final String CHAR_SPACING; static final String WORD_SPACING; static final String WHITESPACE; }
@Test public void tabspaceDocumentTest() throws Exception { Font f = FontFactory.getFont(FontFactory.COURIER, 11); FileOutputStream fs = new FileOutputStream(OUTTABSPACED); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); Paragraph p; writer.setCompressionLevel(0); doc.open(); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); doc.add(p); p = new Paragraph(new Chunk("Hello World!!!")); addTabspaces(p, f, 0); doc.add(p); f.setSize(16); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); doc.add(p); f = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); doc.add(p); f.setSize(20); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); doc.add(p); doc.close(); fs.close(); Assert.assertTrue(compareInnerText(SOURCE11, OUTTABSPACED)); }
@Test public void tabspaceColumnTextTest() throws Exception { Font f = FontFactory.getFont(FontFactory.COURIER, 11); Document doc = new Document(); Paragraph p; FileOutputStream fs = new FileOutputStream(OUTABSPACEC); PdfWriter writer = PdfWriter.getInstance(doc, fs); writer.setCompressionLevel(0); doc.open(); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(36, 36, 436, 800); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); ct.addElement(p); p = new Paragraph(new Chunk("Hello World!!!")); addTabspaces(p, f, 0); ct.addElement(p); f.setSize(16); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); ct.addElement(p); f = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); ct.addElement(p); f.setSize(20); p = new Paragraph(new Chunk("Hello world", f)); addTabspaces(p, f, 0); ct.addElement(p); ct.go(); doc.close(); fs.close(); Assert.assertTrue(compareInnerText(SOURCE12, OUTABSPACEC)); }
@Test public void tabDocumentTest() throws Exception { Font f = FontFactory.getFont(FontFactory.COURIER, 11); FileOutputStream fs = new FileOutputStream(OUTTABD); Document doc = new Document(); PdfWriter writer = PdfWriter.getInstance(doc, fs); Paragraph p; java.util.List<TabStop> tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.CENTER)); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.RIGHT)); writer.setCompressionLevel(0); doc.open(); p = new Paragraph(new Chunk("Hello world", f)); addTabs(p, f, 0, "la|la"); p.setTabSettings(new TabSettings(tabStopsList, 50)); doc.add(p); tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.ANCHOR)); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p = new Paragraph(new Chunk("Hello World!!!")); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 12, "l.aal"); addTabs(p, f, 12, "laa.l"); addTabs(p, f, 12, "la.al"); doc.add(p); f.setSize(16); tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.ANCHOR, ',')); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 13, "l.aal"); addTabs(p, f, 11, "l,aal"); addTabs(p, f, 11, "laa.l"); addTabs(p, f, 11, "laa,l"); doc.add(p); f = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(38)); addTabs(p, f, 0); doc.add(p); f.setSize(20); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(38)); addTabs(p, f, 0); doc.add(p); doc.close(); fs.close(); Assert.assertTrue(compareInnerText(SOURCE13, OUTTABD)); }
@Test public void tabColumnTextTest() throws Exception { Font f = FontFactory.getFont(FontFactory.COURIER, 11); Document doc = new Document(); Paragraph p; FileOutputStream fs = new FileOutputStream(OUTABC); PdfWriter writer = PdfWriter.getInstance(doc, fs); writer.setCompressionLevel(0); doc.open(); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(36, 36, 436, 800); java.util.List<TabStop> tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.CENTER)); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.RIGHT)); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 0, "la|la"); ct.addElement(p); tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.ANCHOR)); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p = new Paragraph(new Chunk("Hello World!!!")); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 12, "l.aal"); addTabs(p, f, 12, "laa.l"); addTabs(p, f, 12, "la.al"); ct.addElement(p); f.setSize(16); p = new Paragraph(new Chunk("Hello world", f)); tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(100, new DottedLineSeparator())); tabStopsList.add(new TabStop(200, new LineSeparator(), TabStop.Alignment.ANCHOR, ',')); tabStopsList.add(new TabStop(300, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 15, "l.aal"); addTabs(p, f, 13, "laa,l"); addTabs(p, f, 13, "laa.l"); addTabs(p, f, 13, "l,aal"); ct.addElement(p); f = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(38)); addTabs(p, f, 0); ct.addElement(p); f.setSize(20); p = new Paragraph(new Chunk("Hello world", f)); p.setTabSettings(new TabSettings(38)); addTabs(p, f, 0); ct.addElement(p); ct.go(); doc.close(); fs.close(); Assert.assertTrue(compareInnerText(SOURCE14, OUTABC)); }
@Test public void tabStopsColumnText() throws Exception{ Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTABSTOPSC)); document.open(); Font oFont1 = FontFactory.getFont(BaseFont.ZAPFDINGBATS, 15, Font.UNDEFINED); Font oFont2 = FontFactory.getFont(BaseFont.COURIER, 15, Font.UNDEFINED); Font oFont3 = FontFactory.getFont(BaseFont.TIMES_ROMAN, 15, Font.UNDEFINED); Font oFont4 = FontFactory.getFont(BaseFont.HELVETICA, 15, Font.UNDEFINED); Image oImg = Image.getInstance("./src/test/resources/com/itextpdf/text/Chunk/logo.gif"); PdfContentByte canvas = writer.getDirectContentUnder(); java.util.List<TabStop> tabStops = new ArrayList<TabStop>(); tabStops.add(new TabStop(200, new DottedLineSeparator())); tabStops.add(new TabStop(400, new DottedLineSeparator())); Paragraph oPara = new Paragraph("Hello World! ", oFont1); oPara.setTabSettings(new TabSettings(tabStops)); oPara.add(new Chunk("iText ® is a library that allows you to create and manipulate PDF documents.", oFont2)); oPara.add(new Chunk("It enables developers looking to enhance web- and other applications with dynamic PDF docu", oFont3)); oPara.add(Chunk.TABBING); oPara.add(new Chunk("ment generation and/or manipulation.", oFont3)); oPara.add(new Chunk(oImg, 0, 0, true)); oPara.add(Chunk.TABBING); oPara.add(new Chunk("Developers can use iText to:", oFont4)); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|100"), 100, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|200"), 200, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|250"), 250, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|300"), 300, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|400"), 400, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|500"), 500, 500, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("|550"), 550, 500, 0); ColumnText oColTxt1 = new ColumnText(canvas); oColTxt1.setSimpleColumn(0, 400, 595, 500); oColTxt1.addElement(oPara); oColTxt1.go(); document.close(); Assert.assertTrue(compareInnerText(SOURCE15, OUTABSTOPSC)); }
@Test public void TabStopOutOfPageBoundDocumentTest() throws DocumentException, IOException { Document doc = new Document(PageSize.A4, 36, 36, 0, 30); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(OUTFOLDER + "/tabStopOutDocument.pdf")); doc.open(); Font f = FontFactory.getFont(FontFactory.COURIER, 11); f.setSize(16); Paragraph p = new Paragraph(Chunk.TABBING); p.add(new Chunk("Hello world", f)); ArrayList<TabStop> tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(1000, new DottedLineSeparator())); tabStopsList.add(new TabStop(1050, new LineSeparator(), TabStop.Alignment.ANCHOR, ',')); tabStopsList.add(new TabStop(1100, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 15, "l.aal"); addTabs(p, f, 13, "laa,l"); addTabs(p, f, 13, "laa.l"); addTabs(p, f, 13, "l,aal"); doc.add(p); doc.close(); writer.close(); Assert.assertTrue(compareInnerText(SOURCE16, OUTFOLDER + "/tabStopOutDocument.pdf")); }
@Test public void TabStopOutOfPageBoundColumnTextTest() throws DocumentException, IOException { Font f = FontFactory.getFont(FontFactory.COURIER, 11); Document doc = new Document(); Paragraph p; FileOutputStream fs = new FileOutputStream(OUTFOLDER + "/tabStopOutColumnText.pdf"); PdfWriter writer = PdfWriter.getInstance(doc, fs); writer.setCompressionLevel(0); doc.open(); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(36, 0, 436, 836); f.setSize(16); p = new Paragraph(Chunk.TABBING); p.add(new Chunk("Hello world", f)); ArrayList<TabStop> tabStopsList = new ArrayList<TabStop>(); tabStopsList.add(new TabStop(1000, new DottedLineSeparator())); tabStopsList.add(new TabStop(1050, new LineSeparator(), TabStop.Alignment.ANCHOR, ',')); tabStopsList.add(new TabStop(1100, new DottedLineSeparator(), TabStop.Alignment.ANCHOR)); p.setTabSettings(new TabSettings(tabStopsList, 50)); addTabs(p, f, 15, "l.aal"); addTabs(p, f, 13, "laa,l"); addTabs(p, f, 13, "laa.l"); addTabs(p, f, 13, "l,aal"); ct.addElement(p); ct.go(); doc.close(); writer.close(); Assert.assertTrue(compareInnerText(SOURCE17, OUTFOLDER + "/tabStopOutColumnText.pdf")); }