/**
  * Parses an HTML source to a List of Element objects
  *
  * @param reader the HTML source
  * @param style a StyleSheet object
  * @param tags a map containing supported tags and their processors
  * @param providers map containing classes with extra info
  * @return a List of Element objects
  * @throws IOException
  * @since 5.0.6
  */
 public static List<Element> parseToList(
     final Reader reader,
     final StyleSheet style,
     final Map<String, HTMLTagProcessor> tags,
     final HashMap<String, Object> providers)
     throws IOException {
   HTMLWorker worker = new HTMLWorker(null, tags, style);
   worker.document = worker;
   worker.setProviders(providers);
   worker.objectList = new ArrayList<Element>();
   worker.parse(reader);
   return worker.objectList;
 }
Ejemplo n.º 2
0
 /**
  * @throws IOException
  * @throws DocumentException
  * @since 5.0.6
  */
 public void simpleSnippet() throws IOException, DocumentException {
   HashMap<String, Object> providers = new HashMap<String, Object>();
   List<Element> parseToList =
       HTMLWorker.parseToList(new StringReader(snippet.toString()), null, providers);
   Document d = new Document(PageSize.A4);
   PdfWriter.getInstance(d, new FileOutputStream(new File("./test.pdf")));
   d.open();
   for (Element e : parseToList) {
     try {
       d.add(e);
     } catch (DocumentException e1) {
       e1.printStackTrace();
       fail("unable to add element " + e);
     }
   }
   d.close();
 }