Java Code Examples for com.lowagie.text.Phrase#add()

The following examples show how to use com.lowagie.text.Phrase#add() . 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: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Creates a Phrase object based on a list of properties.
 * 
 * @param attributes
 * @return a Phrase
 */
public static Phrase getPhrase(Properties attributes) {
	Phrase phrase = new Phrase();
	phrase.setFont(FontFactory.getFont(attributes));
	String value;
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		phrase.setLeading(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT);
	if (value != null) {
		phrase.setLeading(Markup.parseLength(value, Markup.DEFAULT_FONT_SIZE));
	}
	value = attributes.getProperty(ElementTags.ITEXT);
	if (value != null) {
		Chunk chunk = new Chunk(value);
		if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) {
			chunk.setGenericTag(value);
		}
		phrase.add(chunk);
	}
	return phrase;
}
 
Example 2
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Phrase object based on a list of properties.
 * @param attributes
 * @return a Phrase
 */
public static Phrase getPhrase(Properties attributes) {
	Phrase phrase = new Phrase();
	phrase.setFont(FontFactory.getFont(attributes));
	String value;
	value = attributes.getProperty(ElementTags.LEADING);
	if (value != null) {
		phrase.setLeading(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT);
	if (value != null) {
		phrase.setLeading(Markup.parseLength(value,
				Markup.DEFAULT_FONT_SIZE));
	}
	value = attributes.getProperty(ElementTags.ITEXT);
	if (value != null) {
		Chunk chunk = new Chunk(value);
		if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) {
			chunk.setGenericTag(value);
		}
		phrase.add(chunk);
	}
	return phrase;
}
 
Example 3
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeMemoryInformations(MemoryInformations memoryInformations)
		throws BadElementException, IOException {
	addCell(memoryInformations.getMemoryDetails().replace(" Mo", ' ' + getString("Mo")));
	final long usedPermGen = memoryInformations.getUsedPermGen();
	if (usedPermGen > 0) {
		// perm gen est à 0 sous jrockit
		final long maxPermGen = memoryInformations.getMaxPermGen();
		addCell(getString("Memoire_Perm_Gen") + ':');
		if (maxPermGen > 0) {
			final Phrase permGenPhrase = new Phrase(
					integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo")
							+ DIVIDE + integerFormat.format(maxPermGen / 1024 / 1024) + ' '
							+ getString("Mo") + BAR_SEPARATOR,
					cellFont);
			final Image permGenImage = Image.getInstance(
					Bar.toBarWithAlert(memoryInformations.getUsedPermGenPercentage()), null);
			permGenImage.scalePercent(50);
			permGenPhrase.add(new Chunk(permGenImage, 0, 0));
			currentTable.addCell(permGenPhrase);
		} else {
			addCell(integerFormat.format(usedPermGen / 1024 / 1024) + ' ' + getString("Mo"));
		}
	}
}
 
Example 4
Source File: PdfJndiReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeJndiBinding(JndiBinding jndiBinding) throws BadElementException, IOException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final String name = jndiBinding.getName();
	final String className = jndiBinding.getClassName();
	final String contextPath = jndiBinding.getContextPath();
	final String value = jndiBinding.getValue();
	if (contextPath != null) {
		final Image image = getFolderImage();
		final Phrase phrase = new Phrase("", cellFont);
		phrase.add(new Chunk(image, 0, 0));
		phrase.add(new Chunk(" " + name));
		addCell(phrase);
	} else {
		addCell(name);
	}
	addCell(className != null ? className : "");
	addCell(value != null ? value : "");
}
 
Example 5
Source File: JRPdfExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
protected Phrase getPhrase(AttributedString as, String text, JRPrintText textElement)
{
	Phrase phrase = new Phrase();
	int runLimit = 0;

	AttributedCharacterIterator iterator = as.getIterator();
	Locale locale = getTextLocale(textElement);
	 
	boolean firstChunk = true;
	while(runLimit < text.length() && (runLimit = iterator.getRunLimit()) <= text.length())
	{
		Map<Attribute,Object> attributes = iterator.getAttributes();
		Chunk chunk = getChunk(attributes, text.substring(iterator.getIndex(), runLimit), locale);
		
		if (firstChunk)
		{
			// only set anchor + bookmark for the first chunk in the text
			setAnchor(chunk, textElement, textElement);
		}
		
		JRPrintHyperlink hyperlink = textElement;
		if (hyperlink.getHyperlinkTypeValue() == HyperlinkTypeEnum.NONE)
		{
			hyperlink = (JRPrintHyperlink)attributes.get(JRTextAttribute.HYPERLINK);
		}
		
		setHyperlinkInfo(chunk, hyperlink);
		phrase.add(chunk);

		iterator.setIndex(runLimit);
		firstChunk = false;
	}

	return phrase;
}
 
Example 6
Source File: PdfJobInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeJobTimes(JobInformations jobInformations, CounterRequest counterRequest)
		throws BadElementException, IOException {
	final long elapsedTime = jobInformations.getElapsedTime();
	if (elapsedTime >= 0) {
		final Phrase elapsedTimePhrase = new Phrase(durationFormat.format(elapsedTime),
				cellFont);
		final Image memoryImage = Image
				.getInstance(Bar.toBar(100d * elapsedTime / counterRequest.getMean()), null);
		memoryImage.scalePercent(47);
		elapsedTimePhrase.add(new Chunk("\n"));
		elapsedTimePhrase.add(new Chunk(memoryImage, 0, 0));
		addCell(elapsedTimePhrase);
	} else {
		addCell("");
	}
	if (jobInformations.getPreviousFireTime() != null) {
		addCell(fireTimeFormat.format(jobInformations.getPreviousFireTime()));
	} else {
		addCell("");
	}
	if (jobInformations.getNextFireTime() != null) {
		addCell(fireTimeFormat.format(jobInformations.getNextFireTime()));
	} else {
		addCell("");
	}
	// on n'affiche pas la période si >= 1 jour car ce formateur ne saurait pas l'afficher
	if (jobInformations.getRepeatInterval() > 0
			&& jobInformations.getRepeatInterval() < ONE_DAY_MILLIS) {
		addCell(durationFormat.format(new Date(jobInformations.getRepeatInterval())));
	} else if (jobInformations.getCronExpression() != null) {
		addCell(jobInformations.getCronExpression());
	} else {
		addCell("");
	}
}
 
Example 7
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeTomcatInformations(List<TomcatInformations> tomcatInformationsList)
		throws BadElementException, IOException {
	for (final TomcatInformations tomcatInformations : tomcatInformationsList) {
		if (tomcatInformations.getRequestCount() <= 0) {
			continue;
		}
		addCell("Tomcat " + tomcatInformations.getName() + ':');
		// rq: on n'affiche pas pour l'instant getCurrentThreadCount
		final int currentThreadsBusy = tomcatInformations.getCurrentThreadsBusy();
		final String equal = " = ";
		final Phrase phrase = new Phrase(getString("busyThreads") + equal
				+ integerFormat.format(currentThreadsBusy) + DIVIDE
				+ integerFormat.format(tomcatInformations.getMaxThreads()) + BAR_SEPARATOR,
				cellFont);
		final Image threadsImage = Image.getInstance(Bar.toBarWithAlert(
				100d * currentThreadsBusy / tomcatInformations.getMaxThreads()), null);
		threadsImage.scalePercent(50);
		phrase.add(new Chunk(threadsImage, 0, 0));

		phrase.add(new Chunk('\n' + getString("bytesReceived") + equal
				+ integerFormat.format(tomcatInformations.getBytesReceived()) + '\n'
				+ getString("bytesSent") + equal
				+ integerFormat.format(tomcatInformations.getBytesSent()) + '\n'
				+ getString("requestCount") + equal
				+ integerFormat.format(tomcatInformations.getRequestCount()) + '\n'
				+ getString("errorCount") + equal
				+ integerFormat.format(tomcatInformations.getErrorCount()) + '\n'
				+ getString("processingTime") + equal
				+ integerFormat.format(tomcatInformations.getProcessingTime()) + '\n'
				+ getString("maxProcessingTime") + equal
				+ integerFormat.format(tomcatInformations.getMaxTime())));
		currentTable.addCell(phrase);
	}
}
 
Example 8
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeFileDescriptorCounts(JavaInformations javaInformations)
		throws BadElementException, IOException {
	final long unixOpenFileDescriptorCount = javaInformations.getUnixOpenFileDescriptorCount();
	final long unixMaxFileDescriptorCount = javaInformations.getUnixMaxFileDescriptorCount();
	addCell(getString("nb_fichiers") + ':');
	final Phrase fileDescriptorCountPhrase = new Phrase(
			integerFormat.format(unixOpenFileDescriptorCount) + DIVIDE
					+ integerFormat.format(unixMaxFileDescriptorCount) + BAR_SEPARATOR,
			cellFont);
	final Image fileDescriptorCountImage = Image.getInstance(
			Bar.toBarWithAlert(javaInformations.getUnixOpenFileDescriptorPercentage()), null);
	fileDescriptorCountImage.scalePercent(50);
	fileDescriptorCountPhrase.add(new Chunk(fileDescriptorCountImage, 0, 0));
	currentTable.addCell(fileDescriptorCountPhrase);
}
 
Example 9
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeServerInfo(String serverInfo) throws BadElementException, IOException {
	addCell(getString("Serveur") + ':');
	final Phrase serverInfoPhrase = new Phrase("", cellFont);
	final String applicationServerIconName = HtmlJavaInformationsReport
			.getApplicationServerIconName(serverInfo);
	if (applicationServerIconName != null) {
		final Image applicationServerImage = PdfDocumentFactory
				.getImage("servers/" + applicationServerIconName);
		applicationServerImage.scalePercent(40);
		serverInfoPhrase.add(new Chunk(applicationServerImage, 0, 0));
		serverInfoPhrase.add(new Chunk("   "));
	}
	serverInfoPhrase.add(new Chunk(serverInfo));
	currentTable.addCell(serverInfoPhrase);
}
 
Example 10
Source File: DocStyleUtils.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
/** 
 * 功能说明:为文字填充浅灰色背景</BR> 
 * 修改日期:2011-04-27 
 * @author myclover 
 * @param content   需要填充背景颜色的内容 
 * @param appendStr 不需要填充背景颜色的内容 
 * @return 
 */  
private static Phrase setPhraseStyle(String content , String appendStr){  
    Chunk chunk = new Chunk(content);  
    //填充的背景颜色为浅灰色  
    chunk.setBackground(Color.LIGHT_GRAY);  
    Phrase phrase = new Phrase(chunk);  
    phrase.add(appendStr);  
    return phrase;  
}
 
Example 11
Source File: FontFactoryStylesTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Changing the style of a FontFactory Font.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {


	// step 1: creation of a document-object
	Document document = new Document();

	// step 2: creation of the writer
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontfactorystyles.pdf"));

	// step 3: we open the document
	document.open();

	String fontPathBase = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf").getAbsolutePath();
	// step 4: we add some content
	FontFactory.register(fontPathBase + "/LiberationSans-Regular.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-Italic.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-Bold.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-BoldItalic.ttf");
	
	
	Phrase myPhrase = new Phrase("This is font family Liberation Sans ", FontFactory.getFont("LiberationSans", 8));
	myPhrase.add(new Phrase("italic ", FontFactory.getFont("Arial", 8, Font.ITALIC)));
	myPhrase.add(new Phrase("bold ", FontFactory.getFont("Arial", 8, Font.BOLD)));
	myPhrase.add(new Phrase("bolditalic", FontFactory.getFont("Arial", 8, Font.BOLDITALIC)));
	document.add(myPhrase);

	// step 5: we close the document
	document.close();
}
 
Example 12
Source File: DocStyleUtils.java    From DWSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
/** 
 * 功能说明:设置段落的样式,设置前半截内容和后半截内容格式不一样的段落样式</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;  
}
 
Example 13
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private void writeSummary(JavaInformations javaInformations)
		throws BadElementException, IOException {
	addCell(getString("Host") + ':');
	currentTable.addCell(new Phrase(javaInformations.getHost(), boldCellFont));
	addCell(getString("memoire_utilisee") + ':');
	final MemoryInformations memoryInformations = javaInformations.getMemoryInformations();
	final long usedMemory = memoryInformations.getUsedMemory();
	final long maxMemory = memoryInformations.getMaxMemory();
	final Phrase memoryPhrase = new Phrase(integerFormat.format(usedMemory / 1024 / 1024) + ' '
			+ getString("Mo") + DIVIDE + integerFormat.format(maxMemory / 1024 / 1024) + ' '
			+ getString("Mo") + BAR_SEPARATOR, cellFont);
	final Image memoryImage = Image.getInstance(
			Bar.toBarWithAlert(memoryInformations.getUsedMemoryPercentage()), null);
	memoryImage.scalePercent(50);
	memoryPhrase.add(new Chunk(memoryImage, 0, 0));
	currentTable.addCell(memoryPhrase);
	if (javaInformations.getSessionCount() >= 0) {
		addCell(getString("nb_sessions_http") + ':');
		addCell(integerFormat.format(javaInformations.getSessionCount()));
	}
	addCell(getString("nb_threads_actifs") + "\n(" + getString("Requetes_http_en_cours")
			+ "):");
	addCell(integerFormat.format(javaInformations.getActiveThreadCount()));
	if (!noDatabase) {
		addCell(getString("nb_connexions_actives") + ':');
		addCell(integerFormat.format(javaInformations.getActiveConnectionCount()));
		addCell(getString("nb_connexions_utilisees") + "\n(" + getString("ouvertes") + "):");
		final int usedConnectionCount = javaInformations.getUsedConnectionCount();
		final int maxConnectionCount = javaInformations.getMaxConnectionCount();
		if (maxConnectionCount <= 0) {
			addCell(integerFormat.format(usedConnectionCount));
		} else {
			final Phrase usedConnectionCountPhrase = new Phrase(
					integerFormat.format(usedConnectionCount) + DIVIDE
							+ integerFormat.format(maxConnectionCount) + BAR_SEPARATOR,
					cellFont);
			final Image usedConnectionCountImage = Image.getInstance(
					Bar.toBarWithAlert(javaInformations.getUsedConnectionPercentage()), null);
			usedConnectionCountImage.scalePercent(50);
			usedConnectionCountPhrase.add(new Chunk(usedConnectionCountImage, 0, 0));
			currentTable.addCell(usedConnectionCountPhrase);
		}
	}
	if (javaInformations.getSystemLoadAverage() >= 0) {
		addCell(getString("Charge_systeme") + ':');
		addCell(decimalFormat.format(javaInformations.getSystemLoadAverage()));
	}
	if (javaInformations.getSystemCpuLoad() >= 0) {
		addCell(getString("systemCpuLoad") + ':');
		final Phrase systemCpuLoadPhrase = new Phrase(
				decimalFormat.format(javaInformations.getSystemCpuLoad()) + BAR_SEPARATOR,
				cellFont);
		final Image systemCpuLoadImage = Image
				.getInstance(Bar.toBarWithAlert(javaInformations.getSystemCpuLoad()), null);
		systemCpuLoadImage.scalePercent(50);
		systemCpuLoadPhrase.add(new Chunk(systemCpuLoadImage, 0, 0));
		currentTable.addCell(systemCpuLoadPhrase);
	}
}
 
Example 14
Source File: PdfJavaInformationsReport.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private void writeDetails(JavaInformations javaInformations)
		throws BadElementException, IOException {
	addCell(getString("OS") + ':');
	final Phrase osPhrase = new Phrase("", cellFont);
	final String osIconName = HtmlJavaInformationsReport
			.getOSIconName(javaInformations.getOS());
	final String separator = "   ";
	if (osIconName != null) {
		final Image osImage = PdfDocumentFactory.getImage("servers/" + osIconName);
		osImage.scalePercent(40);
		osPhrase.add(new Chunk(osImage, 0, 0));
		osPhrase.add(new Chunk(separator));
	}
	osPhrase.add(new Chunk(javaInformations.getOS() + " ("
			+ javaInformations.getAvailableProcessors() + ' ' + getString("coeurs") + ')'));
	currentTable.addCell(osPhrase);
	addCell(getString("Java") + ':');
	addCell(javaInformations.getJavaVersion());
	addCell(getString("JVM") + ':');
	final Phrase jvmVersionPhrase = new Phrase(javaInformations.getJvmVersion(), cellFont);
	if (javaInformations.getJvmVersion().contains("Client")) {
		jvmVersionPhrase.add(new Chunk(separator));
		final Image alertImage = PdfDocumentFactory.getImage("alert.png");
		alertImage.scalePercent(50);
		jvmVersionPhrase.add(new Chunk(alertImage, 0, -2));
	}
	currentTable.addCell(jvmVersionPhrase);
	addCell(getString("PID") + ':');
	addCell(javaInformations.getPID());
	if (javaInformations.getUnixOpenFileDescriptorCount() >= 0) {
		writeFileDescriptorCounts(javaInformations);
	}
	final String serverInfo = javaInformations.getServerInfo();
	if (serverInfo != null) {
		writeServerInfo(serverInfo);
		addCell(getString("Contexte_webapp") + ':');
		addCell(javaInformations.getContextPath());
	}
	addCell(getString("Demarrage") + ':');
	addCell(I18N.createDateAndTimeFormat().format(javaInformations.getStartDate()));
	addCell(getString("Arguments_JVM") + ':');
	addCell(javaInformations.getJvmArguments());
	if (javaInformations.getSessionCount() >= 0) {
		addCell(getString("httpSessionsMeanAge") + ':');
		addCell(integerFormat.format(javaInformations.getSessionMeanAgeInMinutes()));
	}
	writeTomcatInformations(javaInformations.getTomcatInformationsList());
	addCell(getString("Gestion_memoire") + ':');
	writeMemoryInformations(javaInformations.getMemoryInformations());
	// on considère que l'espace libre sur le disque dur est celui sur la partition du répertoire temporaire
	addCell(getString("Free_disk_space") + ':');
	addCell(integerFormat.format(javaInformations.getFreeDiskSpaceInTemp() / 1024 / 1024) + ' '
			+ getString("Mo"));
	addCell(getString("Usable_disk_space") + ':');
	addCell(integerFormat.format(javaInformations.getUsableDiskSpaceInTemp() / 1024 / 1024)
			+ ' ' + getString("Mo"));
	writeDatabaseVersionAndDataSourceDetails(javaInformations);
	addCell("");
	addCell("");
}
 
Example 15
Source File: ColumnTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrating the use of ColumnText
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("column.pdf"));

	// step 3: we open the document
	document.open();

	// step 4:

	// we create some content
	BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
	Font font = new Font(bf, 11, Font.NORMAL);

	Phrase unicodes = new Phrase(15, "UNI\n", font);
	Phrase characters = new Phrase(15, "\n", font);
	Phrase names = new Phrase(15, "NAME\n", font);

	for (int i = 0; i < 27; i++) {
		unicodes.add(uni[i] + "\n");
		characters.add(code[i] + "\n");
		names.add(name[i] + "\n");
	}

	// we grab the ContentByte and do some stuff with it
	PdfContentByte cb = writer.getDirectContent();

	ColumnText ct = new ColumnText(cb);
	ct.setSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
	ct.go();
	cb.rectangle(103, 295, 52, 8 + 28 * 15);
	cb.stroke();
	ct.setSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
	ct.go();
	ct.setSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
	ct.go();

	// step 5: we close the document
	document.close();
}
 
Example 16
Source File: PhrasesTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Demonstrates how the class Phrase works.
 * 
 */
@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
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Phrases.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Phrase phrase1 = new Phrase("(1) this is a phrase\n");
	// In this example the leading is passed as a parameter
	Phrase phrase2 = new Phrase(
			24,
			"(2) this is a phrase with leading 24. You can only see the difference if the line is long enough. Do you see it? There is more space between this line and the previous one.\n");
	// When a Font is passed (explicitely or embedded in a chunk),
	// the default leading = 1.5 * size of the font
	Phrase phrase3 = new Phrase(
			"(3) this is a phrase with a red, normal font Courier, size 20. As you can see the leading is automatically changed.\n",
			FontFactory.getFont(FontFactory.COURIER, 20, Font.NORMAL, new Color(255, 0, 0)));
	Phrase phrase4 = new Phrase(new Chunk("(4) this is a phrase\n"));
	Phrase phrase5 = new Phrase(18, new Chunk(
			"(5) this is a phrase in Helvetica, bold, red and size 16 with a given leading of 18 points.\n",
			FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, new Color(255, 0, 0))));
	// A Phrase can contains several chunks with different fonts
	Phrase phrase6 = new Phrase("(6)");
	Chunk chunk = new Chunk(" This is a font: ");
	phrase6.add(chunk);
	phrase6.add(new Chunk("Helvetica", FontFactory.getFont(FontFactory.HELVETICA, 12)));
	phrase6.add(chunk);
	phrase6.add(new Chunk("Times New Roman", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
	phrase6.add(chunk);
	phrase6.add(new Chunk("Courier", FontFactory.getFont(FontFactory.COURIER, 12)));
	phrase6.add(chunk);
	phrase6.add(new Chunk("Symbol", FontFactory.getFont(FontFactory.SYMBOL, 12)));
	phrase6.add(chunk);
	phrase6.add(new Chunk("ZapfDingBats", FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12)));
	Phrase phrase7 = new Phrase("(7) if you don't add a newline yourself, all phrases are glued to eachother!");

	document.add(phrase1);
	document.add(phrase2);
	document.add(phrase3);
	document.add(phrase4);
	document.add(phrase5);
	document.add(phrase6);
	document.add(phrase7);

	// step 5: we close the document
	document.close();
}
 
Example 17
Source File: ImageChunksTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Images wrapped in a Chunk.
 */
@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("imageChunks.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we create a table and add it to the document
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png");
	img.scalePercent(70);
	Chunk ck = new Chunk(img, 0, -5);
	PdfPTable table = new PdfPTable(3);
	PdfPCell cell = new PdfPCell();
	cell.addElement(new Chunk(img, 5, -5));
	cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see an image\non my right");
	table.addCell(cell);
	table.addCell("I see an image\non my left");
	table.addCell(cell);
	table.addCell("I see images\neverywhere");
	table.addCell(cell);
	table.addCell("I see an image\non my right");
	table.addCell(cell);
	table.addCell("I see an image\non my left");

	Phrase p1 = new Phrase("This is an image ");
	p1.add(ck);
	p1.add(" just here.");
	document.add(p1);
	document.add(p1);
	document.add(p1);
	document.add(p1);
	document.add(p1);
	document.add(p1);
	document.add(p1);
	document.add(table);

	// step 5: we close the document
	document.close();
}