1: | using System; | |
2: | using System.IO; | |
3: | using System.util; | |
4: | ||
5: | using iTextSharp.text; | |
6: | using iTextSharp.text.pdf; | |
7: | using iTextSharp.text.xml; | |
8: | using System.Collections; | |
9: | using iTextSharp.text.html; | |
10: | ||
11: | namespace iTextSharp.tutorial.Chap07 | |
12: | { | |
13: | /// <summary> | |
14: | /// Chap0706 ժҪ˵ | |
15: | /// </summary> | |
16: | public class Chap0707 | |
17: | { | |
18: | public Chap0707() | |
19: | { | |
20: | Console.WriteLine("Chapter 7 example 7: parsing the HTML from example 2"); | |
21: | ||
22: | // step 1: creation of a document-object | |
23: | Document document = new Document(PageSize.A4, 80, 50, 30, 65); | |
24: | ||
25: | try | |
26: | { | |
27: | ||
28: | // step 2: | |
29: | // we create a writer that listens to the document | |
30: | // and directs a XML-stream to a file | |
31: | PdfWriter.GetInstance(document, new FileStream("Chap0707.pdf", FileMode.Create)); | |
32: | ||
33: | // // step 3: we create a parser and set the document handler | |
34: | // Parser parser = ParserFactory.makeParser(PARSER); | |
35: | // parser.setDocumentHandler(new SAXmyHtmlHandler(document)); | |
36: | // step 3: we create a parser | |
37: | ||
38: | // ITextHandler h = new ITextHandler(document); | |
39: | HtmlParser.Parse(document,"Chap0702.htm"); | |
40: | ||
41: | // step 4: we parse the document _Document; | |
42: | // h.Parse("Chap0702.htm"); | |
43: | // step 4: we parse the document | |
44: | // parser.parse("Chap0702.html"); | |
45: | ||
46: | } | |
47: | catch(Exception e) | |
48: | { | |
49: | Console.Error.WriteLine(e.Message); | |
50: | Console.Error.WriteLine(e.StackTrace); | |
51: | } | |
52: | } | |
53: | } | |
54: | } |