| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap10 | |
| 8: | { | |
| 9: | public class Chap1014 | |
| 10: | { | |
| 11: | ||
| 12: | ||
| 13: | public Chap1014() | |
| 14: | { | |
| 15: | ||
| 16: | Console.WriteLine("Chapter 10 Example 14: colored patterns"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 20: | Document.Compress = false; | |
| 21: | try | |
| 22: | { | |
| 23: | ||
| 24: | // step 2: | |
| 25: | // we create a writer that listens to the document | |
| 26: | // and directs a PDF-stream to a file | |
| 27: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1014.pdf", FileMode.Create)); | |
| 28: | ||
| 29: | // step 3: we open the document | |
| 30: | document.Open(); | |
| 31: | ||
| 32: | // step 4: we add some content | |
| 33: | PdfContentByte cb = writer.DirectContent; | |
| 34: | PdfTemplate tp = cb.CreateTemplate(400, 300); | |
| 35: | PdfPatternPainter pat = cb.CreatePattern(15, 15, null); | |
| 36: | pat.Rectangle(5, 5, 5, 5); | |
| 37: | pat.Fill(); | |
| 38: | PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f)); | |
| 39: | SpotColor spot = new SpotColor(spc_cmyk); | |
| 40: | tp.SetPatternFill(pat, spot, .9f); | |
| 41: | tp.Rectangle(0, 0, 400, 300); | |
| 42: | tp.Fill(); | |
| 43: | cb.AddTemplate(tp, 50, 50); | |
| 44: | PdfPatternPainter pat2 = cb.CreatePattern(10, 10, null); | |
| 45: | pat2.SetLineWidth(2); | |
| 46: | pat2.MoveTo(-5, 0); | |
| 47: | pat2.LineTo(10, 15); | |
| 48: | pat2.Stroke(); | |
| 49: | pat2.MoveTo(0, -5); | |
| 50: | pat2.LineTo(15, 10); | |
| 51: | pat2.Stroke(); | |
| 52: | cb.SetLineWidth(1); | |
| 53: | cb.SetColorStroke( new Color(System.Drawing.Color.Black)); | |
| 54: | cb.SetPatternFill(pat2, new Color(System.Drawing.Color.Red)); | |
| 55: | cb.Rectangle(100, 400, 30, 210); | |
| 56: | cb.FillStroke(); | |
| 57: | cb.SetPatternFill(pat2, new Color(System.Drawing.Color.LightGreen)); | |
| 58: | cb.Rectangle(150, 400, 30, 100); | |
| 59: | cb.FillStroke(); | |
| 60: | cb.SetPatternFill(pat2, new Color(System.Drawing.Color.Blue)); | |
| 61: | cb.Rectangle(200, 400, 30, 130); | |
| 62: | cb.FillStroke(); | |
| 63: | cb.SetPatternFill(pat2, new GrayColor(0.5f)); | |
| 64: | cb.Rectangle(250, 400, 30, 80); | |
| 65: | cb.FillStroke(); | |
| 66: | cb.SetPatternFill(pat2, new GrayColor(0.7f)); | |
| 67: | cb.Rectangle(300, 400, 30, 170); | |
| 68: | cb.FillStroke(); | |
| 69: | cb.SetPatternFill(pat2, new GrayColor(0.9f)); | |
| 70: | cb.Rectangle(350, 400, 30, 40); | |
| 71: | cb.FillStroke(); | |
| 72: | } | |
| 73: | catch (Exception de) | |
| 74: | { | |
| 75: | Console.Error.WriteLine(de.Message); | |
| 76: | Console.Error.WriteLine(de.StackTrace); | |
| 77: | } | |
| 78: | // step 5: we close the document | |
| 79: | document.Close(); | |
| 80: | } | |
| 81: | } | |
| 82: | } |