Java 类com.lowagie.text.Header 实例源码

项目:itext2    文件:HtmlWriter.java   
/**
* Writes a Metatag in the header.
*
* @param   meta   the element that has to be written
* @throws  IOException
*/

   protected void writeHeader(Meta meta) throws IOException {
       addTabs(2);
       writeStart(HtmlTags.META);
       switch(meta.type()) {
           case Element.HEADER:
               write(HtmlTags.NAME, ((Header) meta).getName());
               break;
           case Element.SUBJECT:
               write(HtmlTags.NAME, HtmlTags.SUBJECT);
               break;
           case Element.KEYWORDS:
               write(HtmlTags.NAME, HtmlTags.KEYWORDS);
               break;
           case Element.AUTHOR:
               write(HtmlTags.NAME, HtmlTags.AUTHOR);
               break;
       }
       write(HtmlTags.CONTENT, HtmlEncoder.encode(meta.getContent()));
       writeEnd();
   }
项目:DroidText    文件:HtmlWriter.java   
/**
 * Writes a Metatag in the header.
 * 
 * @param meta
 *            the element that has to be written
 * @throws IOException
 */

protected void writeHeader(Meta meta) throws IOException {
    addTabs(2);
    writeStart(HtmlTags.META);
    switch (meta.type()) {
    case Element.HEADER:
        write(HtmlTags.NAME, ((Header) meta).getName());
        break;
    case Element.SUBJECT:
        write(HtmlTags.NAME, HtmlTags.SUBJECT);
        break;
    case Element.KEYWORDS:
        write(HtmlTags.NAME, HtmlTags.KEYWORDS);
        break;
    case Element.AUTHOR:
        write(HtmlTags.NAME, HtmlTags.AUTHOR);
        break;
    }
    write(HtmlTags.CONTENT, HtmlEncoder.encode(meta.getContent()));
    writeEnd();
}
项目:itext2    文件:HtmlWriter.java   
/**
* Writes a link in the header.
*
* @param   header   the element that has to be written
* @throws  IOException
*/

   protected void writeLink(Header header) throws IOException {
       addTabs(2);
       writeStart(HtmlTags.LINK);
       write(HtmlTags.REL, header.getName());
       write(HtmlTags.TYPE, HtmlTags.TEXT_CSS);
       write(HtmlTags.REFERENCE, header.getContent());
       writeEnd();
   }
项目:itext2    文件:HtmlWriter.java   
/**
* Writes a JavaScript section or, if the markup attribute HtmlTags.URL is set, a JavaScript reference in the header.
*
* @param   header   the element that has to be written
* @throws  IOException
*/

   protected void writeJavaScript(Header header) throws IOException {
       addTabs(2);
       writeStart(HtmlTags.SCRIPT);
       write(HtmlTags.LANGUAGE, HtmlTags.JAVASCRIPT);
       if (markup.size() > 0) {
         /* JavaScript reference example:
          *
          * <script language="JavaScript" src="/myPath/MyFunctions.js"/>
          */ 
         writeMarkupAttributes(markup);
         os.write(GT);
         writeEnd(HtmlTags.SCRIPT);
       }
       else {
         /* JavaScript coding convention:
          *
          * <script language="JavaScript" type="text/javascript">
          * <!--
          * // ... JavaScript methods ...
          * //-->
          * </script>
          */ 
         write(HtmlTags.TYPE, Markup.HTML_VALUE_JAVASCRIPT);
         os.write(GT);
         addTabs(2);
         write(new String(BEGINCOMMENT) + "\n");
         write(header.getContent());
         addTabs(2);
         write("//" + new String(ENDCOMMENT));
         addTabs(2);
         writeEnd(HtmlTags.SCRIPT);
       }
   }
项目:DroidText    文件:HtmlWriter.java   
/**
 * Writes a link in the header.
 * 
 * @param header
 *            the element that has to be written
 * @throws IOException
 */

protected void writeLink(Header header) throws IOException {
    addTabs(2);
    writeStart(HtmlTags.LINK);
    write(HtmlTags.REL, header.getName());
    write(HtmlTags.TYPE, HtmlTags.TEXT_CSS);
    write(HtmlTags.REFERENCE, header.getContent());
    writeEnd();
}
项目:DroidText    文件:HtmlWriter.java   
/**
 * Writes a JavaScript section or, if the markup attribute HtmlTags.URL is
 * set, a JavaScript reference in the header.
 * 
 * @param header
 *            the element that has to be written
 * @throws IOException
 */

protected void writeJavaScript(Header header) throws IOException {
    addTabs(2);
    writeStart(HtmlTags.SCRIPT);
    write(HtmlTags.LANGUAGE, HtmlTags.JAVASCRIPT);
    if (markup.size() > 0) {
        /*
         * JavaScript reference example:
         * 
         * <script language="JavaScript" src="/myPath/MyFunctions.js"/>
         */
        writeMarkupAttributes(markup);
        os.write(GT);
        writeEnd(HtmlTags.SCRIPT);
    } else {
        /*
         * JavaScript coding convention:
         * 
         * <script language="JavaScript" type="text/javascript"> <!-- // ...
         * JavaScript methods ... //--> </script>
         */
        write(HtmlTags.TYPE, Markup.HTML_VALUE_JAVASCRIPT);
        os.write(GT);
        addTabs(2);
        write(new String(BEGINCOMMENT) + "\n");
        write(header.getContent());
        addTabs(2);
        write("//" + new String(ENDCOMMENT));
        addTabs(2);
        writeEnd(HtmlTags.SCRIPT);
    }
}
项目:itext2    文件:JavaScriptActionTest.java   
/**
 * Creates a document with Named Actions.
 * 
 */
@Test
public void main() throws Exception {

    // step 1: creation of a document-object
    Document document = new Document();

    // step 2:
    HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("JavaScriptAction.html"));
    // step 3: we add Javascript as Metadata and we open the document

    StringBuffer javaScriptSection = new StringBuffer();
    javaScriptSection.append("\t\tfunction load() {\n");
    javaScriptSection.append("\t\t  alert('Page has been loaded.');\n");
    javaScriptSection.append("\t\t}\n");

    javaScriptSection.append("\t\tfunction unload(){\n");
    javaScriptSection.append("\t\t  alert('Page has been unloaded.');\n");
    javaScriptSection.append("\t\t}\n");

    javaScriptSection.append("\t\tfunction sayHi(){\n");
    javaScriptSection.append("\t\t  alert('Hi !!!');\n");
    javaScriptSection.append("\t\t}");

    document.add(new Header(HtmlTags.JAVASCRIPT, javaScriptSection.toString()));
    document.setJavaScript_onLoad("load()");
    document.setJavaScript_onUnLoad("unload()");

    document.open();
    // step 4: we add some content
    Phrase phrase1 = new Phrase(
            "There are 3 JavaScript functions in the HTML page, load(), unload() and sayHi().\n\n"
                    + "The first one will be called when the HTML page has been loaded by your browser.\n"
                    + "The second one will be called when the HTML page is being unloaded,\n"
                    + "for example when you go to another page.\n");
    document.add(phrase1);

    // add a HTML link <A HREF="...">
    Anchor anchor = new Anchor("Click here to execute the third JavaScript function.");
    anchor.setReference("JavaScript:sayHi()");
    document.add(anchor);

    // step 5: we close the document
    document.close();

}