1: | using System; | |
2: | using System.IO; | |
3: | using System.Drawing.Imaging; | |
4: | ||
5: | using iTextSharp.text; | |
6: | using iTextSharp.text.pdf; | |
7: | ||
8: | namespace iTextSharp.tutorial.Chap06 | |
9: | { | |
10: | /// <summary> | |
11: | /// TIFF and CCITT | |
12: | /// </summary> | |
13: | public class Chap0611 | |
14: | { | |
15: | ||
16: | public Chap0611() | |
17: | { | |
18: | // creation of the document with a certain size and certain margins | |
19: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
20: | //Document.compress = false; | |
21: | try | |
22: | { | |
23: | // creation of the different writers | |
24: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0611.pdf", FileMode.Create)); | |
25: | ||
26: | System.Drawing.Bitmap bm = new System.Drawing.Bitmap("338814-00.tif"); | |
27: | int total = bm.GetFrameCount(FrameDimension.Page); | |
28: | ||
29: | Console.WriteLine("Number of images in this TIFF: " + total); | |
30: | ||
31: | // Which of the multiple images in the TIFF file do we want to load | |
32: | // 0 refers to the first, 1 to the second and so on. | |
33: | document.Open(); | |
34: | PdfContentByte cb = writer.DirectContent; | |
35: | for (int k = 0; k < total; ++k) | |
36: | { | |
37: | bm.SelectActiveFrame(FrameDimension.Page, k); | |
38: | Image img = Image.GetInstance(bm, null, true); | |
39: | img.ScalePercent(72f / 200f * 100); | |
40: | img.SetAbsolutePosition(0, 0); | |
41: | Console.WriteLine("Image: " + k); | |
42: | cb.AddImage(img); | |
43: | document.NewPage(); | |
44: | } | |
45: | document.Close(); | |
46: | } | |
47: | catch (Exception de) | |
48: | { | |
49: | Console.Error.WriteLine(de.Message); | |
50: | Console.Error.WriteLine(de.StackTrace); | |
51: | } | |
52: | } | |
53: | } | |
54: | } |