| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap06 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Positioning the Image | |
| 11: | /// Images and text | |
| 12: | /// you can also specify that text has to be wrapped around the image | |
| 13: | /// </summary> | |
| 14: | public class Chap0605 | |
| 15: | { | |
| 16: | public Chap0605() | |
| 17: | { | |
| 18: | Console.WriteLine("Chapter 6 example 5: Alignment of images"); | |
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(); | |
| 21: | try | |
| 22: | { | |
| 23: | // step 2: | |
| 24: | // we create a writer that listens to the document | |
| 25: | // and directs a PDF-stream to a file | |
| 26: | PdfWriter.GetInstance(document, new FileStream("Chap0605.pdf", FileMode.Create)); | |
| 27: | ||
| 28: | // step 3: we open the document | |
| 29: | document.Open(); | |
| 30: | ||
| 31: | Image gif = Image.GetInstance("vonnegut.gif"); | |
| 32: | gif.Alignment = Image.RIGHT_ALIGN | Image.TEXTWRAP; | |
| 33: | Image jpeg = Image.GetInstance("myKids.jpg"); | |
| 34: | jpeg.Alignment = Image.MIDDLE_ALIGN; | |
| 35: | Image png = Image.GetInstance("hitchcock.png"); | |
| 36: | png.Alignment = Image.LEFT_ALIGN | Image.UNDERLYING; | |
| 37: | ||
| 38: | for (int i = 0; i < 100; i++) | |
| 39: | { | |
| 40: | document.Add(new Phrase("Who is this? ")); | |
| 41: | } | |
| 42: | document.Add(gif); | |
| 43: | for (int i = 0; i < 100; i++) | |
| 44: | { | |
| 45: | document.Add(new Phrase("Who is this? ")); | |
| 46: | } | |
| 47: | document.Add(jpeg); | |
| 48: | for (int i = 0; i < 100; i++) | |
| 49: | { | |
| 50: | document.Add(new Phrase("Who is this? ")); | |
| 51: | } | |
| 52: | document.Add(png); | |
| 53: | for (int i = 0; i < 100; i++) | |
| 54: | { | |
| 55: | document.Add(new Phrase("Who is this? ")); | |
| 56: | } | |
| 57: | document.Add(gif); | |
| 58: | for (int i = 0; i < 100; i++) | |
| 59: | { | |
| 60: | document.Add(new Phrase("Who is this? ")); | |
| 61: | } | |
| 62: | document.Add(jpeg); | |
| 63: | for (int i = 0; i < 100; i++) | |
| 64: | { | |
| 65: | document.Add(new Phrase("Who is this? ")); | |
| 66: | } | |
| 67: | document.Add(png); | |
| 68: | for (int i = 0; i < 100; i++) | |
| 69: | { | |
| 70: | document.Add(new Phrase("Who is this? ")); | |
| 71: | } | |
| 72: | } | |
| 73: | catch(DocumentException de) | |
| 74: | { | |
| 75: | Console.WriteLine(de.Message); | |
| 76: | } | |
| 77: | catch(IOException ioe) | |
| 78: | { | |
| 79: | Console.WriteLine(ioe.Message); | |
| 80: | } | |
| 81: | // step 5: we close the document | |
| 82: | document.Close(); | |
| 83: | } | |
| 84: | } | |
| 85: | } |