Skip navigation links
com.lowagie.text.html

Class HtmlWriter

    • Field Detail

      • BEGINCOMMENT

        public static final byte[] BEGINCOMMENT
        This is a possible HTML-tag.
      • ENDCOMMENT

        public static final byte[] ENDCOMMENT
        This is a possible HTML-tag.
      • currentfont

        protected Stack<Font> currentfont
        This is the current font of the HTML.
      • standardfont

        protected Font standardfont
        This is the standard font of the HTML.
      • imagepath

        protected String imagepath
        This is a path for images.
      • pageN

        protected int pageN
        Stores the page number.
      • header

        protected HeaderFooter header
        This is the textual part of a header
      • footer

        protected HeaderFooter footer
        This is the textual part of the footer
      • markup

        protected Properties markup
        Store the markup properties of a MarkedObject.
    • Constructor Detail

      • HtmlWriter

        protected HtmlWriter(Document doc,
                             OutputStream os)
        Constructs a HtmlWriter.
        Parameters:
        doc - The Document that has to be written as HTML
        os - The OutputStream the writer has to write to.
    • Method Detail

      • getInstance

        public static HtmlWriter getInstance(Document document,
                                             OutputStream os)
        Gets an instance of the HtmlWriter.
        Parameters:
        document - The Document that has to be written
        os - The OutputStream the writer has to write to.
        Returns:
        a new HtmlWriter
      • newPage

        public boolean newPage()
        Signals that an new page has to be started.
        Specified by:
        newPage in interface DocListener
        Overrides:
        newPage in class DocWriter
        Returns:
        true if this action succeeded, false if not.
      • add

        public boolean add(Element element)
                    throws DocumentException
        Signals that an Element was added to the Document.
        Specified by:
        add in interface ElementListener
        Overrides:
        add in class DocWriter
        Parameters:
        element - a high level object that has to be translated to HTML
        Returns:
        true if the element was added, false if not.
        Throws:
        DocumentException - when a document isn't open yet, or has been closed
      • open

        public void open()
        Signals that the Document has been opened and that Elements can be added.

        The HEAD-section of the HTML-document is written.

        Specified by:
        open in interface DocListener
        Overrides:
        open in class DocWriter
      • close

        public void close()
        Signals that the Document was closed and that no other Elements will be added.
        Specified by:
        close in interface DocListener
        Overrides:
        close in class DocWriter
      • initHeader

        protected void initHeader()
        Adds the header to the top of the Document
      • initFooter

        protected void initFooter()
        Adds the header to the top of the Document
      • writeHeader

        protected void writeHeader(Meta meta)
                            throws IOException
        Writes a Metatag in the header.
        Parameters:
        meta - the element that has to be written
        Throws:
        IOException
      • writeLink

        protected void writeLink(Header header)
                          throws IOException
        Writes a link in the header.
        Parameters:
        header - the element that has to be written
        Throws:
        IOException
      • writeJavaScript

        protected void writeJavaScript(Header header)
                                throws IOException
        Writes a JavaScript section or, if the markup attribute HtmlTags.URL is set, a JavaScript reference in the header.
        Parameters:
        header - the element that has to be written
        Throws:
        IOException
      • writeComment

        protected void writeComment(String comment)
                             throws IOException
        Writes some comment.

        This method writes some comment.

        Parameters:
        comment - the comment that has to be written
        Throws:
        IOException
      • setStandardFont

        public void setStandardFont(Font standardfont)
        Changes the standardfont.
        Parameters:
        standardfont - The font
      • isOtherFont

        public boolean isOtherFont(@Nullable
                                   Font font)
        Checks if a given font is the same as the font that was last used.
        Parameters:
        font - the font of an object
        Returns:
        true if the font differs
      • setImagepath

        public void setImagepath(String imagepath)
        Sets the basepath for images.

        This is especially useful if you add images using a file, rather than an URL. In PDF there is no problem, since the images are added inline, but in HTML it is sometimes necessary to use a relative path or a special path to some images directory.

        Parameters:
        imagepath - the new imagepath
      • resetImagepath

        public void resetImagepath()
        Resets the imagepath.
      • add

        public boolean add(String string)
        Signals that a String was added to the Document.
        Parameters:
        string - a String to add to the HTML
        Returns:
        true if the string was added, false if not.
      • write

        protected void write(Element element,
                             int indent)
                      throws IOException
        Writes the HTML representation of an element.
        Parameters:
        element - the element
        indent - the indentation
        Throws:
        IOException
      • writeSection

        protected void writeSection(Section section,
                                    int indent)
                             throws IOException
        Writes the HTML representation of a section.
        Parameters:
        section - the section to write
        indent - the indentation
        Throws:
        IOException
      • writeCssProperty

        protected void writeCssProperty(String prop,
                                        String value)
                                 throws IOException
        Writes out a CSS property.
        Parameters:
        prop - a CSS property
        value - the value of the CSS property
        Throws:
        IOException

Copyright © 2019. All rights reserved.