The
com.itextpdf.text.Phrase
class in IText represents a "phrase" of text. The Phrase
class knows how to add spacing between lines.
Here is a simple code example:
import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; public class DocumentExample { public static void main(String[] args) { Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("Phrase.pdf")); document.open(); document.add(new Phrase("This is sentence 1. ")); document.add(new Phrase("This is sentence 2. ")); document.add(new Phrase("This is sentence 3. ")); document.add(new Phrase("This is sentence 4. ")); document.add(new Phrase("This is sentence 5. ")); document.add(new Phrase("This is sentence 6. ")); document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
Here is what the generated document looks like:
An IText Phrase example |
Notice how sentence 6 is nicely located on its own line.
沒有留言:
張貼留言