com.lowagie.text.Header Java Examples

The following examples show how to use com.lowagie.text.Header. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* 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();
   }
 
Example #3
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #4
Source File: HtmlWriter.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example #5
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* 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();
   }
 
Example #6
Source File: HtmlWriter.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* 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);
       }
   }
 
Example #7
Source File: JavaScriptActionTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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();

}