XML / NOTES</>↗XML10 Jan 2012
This example will show you how to parse an XML file using SAX parser and build an object graph from the parsed XML. We will read the records.xml file that contains some recording information and create the Record object from it. The DefaultHandler in this example created as an anonymous class. We override some method […]
APACHE COMMONS / NOTES</>↗Apache Commons09 Jan 2012
The code snippet below uses the FileUtils.toFile(URL) method that can be found in the Apache Commons IO library to convert a URL into a File. The url protocol should be file or else null will be returned. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Objects; public class URLToFileObject { public static […]
XML / NOTES</>↗XML09 Jan 2012
This example show you how to read / parse an xml file using the SAX (Simple API for XML) parser. In the main class (SAXDemo) we create the instance of SAXParserFactory and the SAXParser. The SAXParser.parse() method will parse the given InputStream and handle the xml document using the SAXHandler class that we created. package […]
ITEXT PDF / NOTES</>↗iText PDF28 Dec 2011
The following example you’ll see how to create a superscript and subscript text in the pdf document using iText. We can use the Chunk‘s class method called setTextRise(). A positive value will create a superscript text while a negative value will create a subscript text. package org.kodejava.itextpdf; import com.itextpdf.text.*; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; […]
ITEXT PDF / NOTES</>↗iText PDF28 Dec 2011
You can use the Chunk‘s setUnderline(float thickness, float yPosition) method to add underline or strike through to a chunk. A negative value to the yPosition create an underline while a positive value will produce a strike through. package org.kodejava.itextpdf; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileNotFoundException; import java.io.FileOutputSt...
ITEXT PDF / NOTES</>↗iText PDF28 Dec 2011
We can set font style for text object such as Chunk, Phrase, Paragraph, etc. using the com.itextpdf.text.Font class. We can define the font face, size, style and its color using this class. package org.kodejava.itextpdf; import com.itextpdf.text.*; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class FontDemo { public static void main(String[] args) { Document doc = […]