Blog

 
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:       /// Scaling and Rotating the Image:
11:       /// Rotating
12:       /// </summary>
13:       public class Chap0608 
14:       {
15:       
16:           public Chap0608() 
17:           {
18:           
19:               Console.WriteLine("Chapter 6 example 8: Rotating an Image");
20:           
21:               // step 1: creation of a document-object
22:               Document document new Document();
23:           
24:               try 
25:               {
26:               
27:                   // step 2:
28:                   // we create a writer that listens to the document
29:                   // and directs a PDF-stream to a file
30:               
31:                   PdfWriter.GetInstance(documentnew FileStream("Chap0608.pdf"FileMode.Create));
32:               
33:                   // step 3: we open the document
34:                   document.Open();
35:               
36:                   // step 4: we add content
37:                   Image jpg Image.GetInstance("myKids.jpg");
38:                   jpg.Alignment Image.MIDDLE_ALIGN;
39:                   
40:                   jpg.Rotation=((float)Math.PI 6);
41:                   document.Add(new Paragraph("rotate 30 degrees"));
42:                   document.Add(jpg);
43:                   document.NewPage();
44:               
45:                   jpg.Rotation=((float)Math.PI 4);
46:                   document.Add(new Paragraph("rotate 45 degrees"));
47:                   document.Add(jpg);
48:                   document.NewPage();
49:               
50:                   jpg.Rotation=((float)Math.PI 2);
51:                   document.Add(new Paragraph("rotate pi/2 radians"));
52:                   document.Add(jpg);
53:                   document.NewPage();
54:               
55:                   jpg.Rotation=((float)(Math.PI 0.75));
56:                   document.Add(new Paragraph("rotate 135 degrees"));
57:                   document.Add(jpg);
58:                   document.NewPage();
59:               
60:                   jpg.Rotation=((float)Math.PI);
61:                   document.Add(new Paragraph("rotate pi radians"));
62:                   document.Add(jpg);
63:                   document.NewPage();
64:               
65:                   jpg.Rotation=((float)(2.0 Math.PI));
66:                   document.Add(new Paragraph("rotate 2 x pi radians"));
67:                   document.Add(jpg);
68:               }
69:               catch(DocumentException de
70:               {
71:                   Console.Error.WriteLine(de.Message);
72:               }
73:               catch(IOException ioe
74:               {
75:                   Console.Error.WriteLine(ioe.Message);
76:               }
77:           
78:               // step 5: we close the document
79:               document.Close();
80:           }
81:       }
82:   }