Class WordDocument

java.lang.Object
com.independentsoft.office.OfficeDocument
com.independentsoft.office.word.WordDocument

public class WordDocument extends OfficeDocument
The Class WordDocument.
  • Constructor Details

  • Method Details

    • open

      public void open(String filePath) throws IOException, XMLStreamException
      Description copied from class: OfficeDocument
      Open.
      Specified by:
      open in class OfficeDocument
      Parameters:
      filePath - the file
      Throws:
      IOException - Signals that an I/O exception has occurred.
      XMLStreamException - the xML stream exception
    • open

      public void open(InputStream inputStream) throws IOException, XMLStreamException
      Description copied from class: OfficeDocument
      Open.
      Specified by:
      open in class OfficeDocument
      Parameters:
      inputStream - the stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
      XMLStreamException - the xML stream exception
    • loadFromDoc

      public void loadFromDoc(String file) throws IOException
      Loads a DOC (Microsoft Word 97-2003 binary format) document and reconstructs its content (text, character/paragraph formatting, styles, tables, fields and embedded PNG/JPEG images) into this document.
      Parameters:
      file - the DOC file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadFromDoc

      public void loadFromDoc(InputStream stream) throws IOException
      Loads a DOC document from a stream. See loadFromDoc(String).
      Parameters:
      stream - the DOC stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadFromRtf

      public void loadFromRtf(String file) throws IOException
      Loads an RTF (Rich Text Format) document and reconstructs its content (text, character/paragraph formatting, tables and embedded PNG/JPEG images) into this document.
      Parameters:
      file - the RTF file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadFromRtf

      public void loadFromRtf(InputStream stream) throws IOException
      Loads an RTF document from a stream. See loadFromRtf(String).
      Parameters:
      stream - the RTF stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadFromRtfString

      public void loadFromRtfString(String rtfContent)
      Loads an RTF document from an RTF markup string.
      Parameters:
      rtfContent - the RTF markup
    • openImplementation

      protected void openImplementation(InputStream inputStream) throws IOException, XMLStreamException
      Overrides:
      openImplementation in class OfficeDocument
      Throws:
      IOException
      XMLStreamException
    • save

      public void save(String filePath) throws IOException
      Description copied from class: OfficeDocument
      Save.
      Specified by:
      save in class OfficeDocument
      Parameters:
      filePath - the file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public void save(String filePath, boolean overwrite) throws IOException
      Description copied from class: OfficeDocument
      Save.
      Specified by:
      save in class OfficeDocument
      Parameters:
      filePath - the file
      overwrite - the overwrite
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • save

      public void save(OutputStream outputStream) throws IOException
      Description copied from class: OfficeDocument
      Save.
      Specified by:
      save in class OfficeDocument
      Parameters:
      outputStream - the stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public void saveAsHtml(String filePath) throws IOException
      Save the document as HTML to the specified file path.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public void saveAsHtml(String filePath, boolean overwrite) throws IOException
      Save the document as HTML to the specified file path.
      Parameters:
      filePath - the file path
      overwrite - whether to overwrite existing file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsHtml

      public void saveAsHtml(OutputStream outputStream) throws IOException
      Save the document as HTML to the specified output stream.
      Parameters:
      outputStream - the output stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getHtml

      public String getHtml()
      Get HTML representation of the document.
      Returns:
      HTML string representation of the document
    • saveAsPdf

      public void saveAsPdf(String filePath) throws IOException
      Save the document as PDF to the specified file path.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsPdf

      public void saveAsPdf(String filePath, PdfSaveOptions options) throws IOException
      Save the document as PDF to the specified file path.
      Parameters:
      filePath - the file path
      options - the PDF export options
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsPdf

      public void saveAsPdf(String filePath, boolean overwrite) throws IOException
      Save the document as PDF to the specified file path.
      Parameters:
      filePath - the file path
      overwrite - whether to overwrite existing file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsPdf

      public void saveAsPdf(String filePath, boolean overwrite, PdfSaveOptions options) throws IOException
      Save the document as PDF to the specified file path.
      Parameters:
      filePath - the file path
      overwrite - whether to overwrite existing file
      options - the PDF export options
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsPdf

      public void saveAsPdf(OutputStream outputStream) throws IOException
      Save the document as PDF to the specified output stream.
      Parameters:
      outputStream - the output stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsPdf

      public void saveAsPdf(OutputStream outputStream, PdfSaveOptions options) throws IOException
      Save the document as PDF to the specified output stream.
      Parameters:
      outputStream - the output stream
      options - the PDF export options
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsRtf

      public void saveAsRtf(String filePath) throws IOException
      Save the document as RTF to the specified file path.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsRtf

      public void saveAsRtf(String filePath, boolean overwrite) throws IOException
      Save the document as RTF to the specified file path.
      Parameters:
      filePath - the file path
      overwrite - whether to overwrite existing file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsRtf

      public void saveAsRtf(OutputStream outputStream) throws IOException
      Save the document as RTF to the specified output stream.
      Parameters:
      outputStream - the output stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getRtf

      public String getRtf()
      Get RTF representation of the document.
      Returns:
      RTF string representation of the document
    • saveAsMarkdown

      public void saveAsMarkdown(String filePath) throws IOException
      Save the document as Markdown to the specified file path.
      Parameters:
      filePath - the file path
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsMarkdown

      public void saveAsMarkdown(String filePath, boolean overwrite) throws IOException
      Save the document as Markdown to the specified file path.
      Parameters:
      filePath - the file path
      overwrite - whether to overwrite existing file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • saveAsMarkdown

      public void saveAsMarkdown(OutputStream outputStream) throws IOException
      Save the document as Markdown to the specified output stream.
      Parameters:
      outputStream - the output stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getMarkdown

      public String getMarkdown()
      Get Markdown representation of the document.
      Returns:
      Markdown string representation of the document
    • loadFromHtml

      public void loadFromHtml(String filePath) throws IOException
      Load HTML content from a file and convert it to Word document structure. This replaces the current document content.
      Parameters:
      filePath - the path to the HTML file
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • loadFromHtml

      public void loadFromHtml(InputStream inputStream) throws IOException
      Load HTML content from an input stream and convert it to Word document structure. This replaces the current document content.
      Parameters:
      inputStream - the input stream containing HTML content
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • importHtml

      public void importHtml(String htmlContent)
      Import HTML string content and convert it to Word document structure. This replaces the current document content.
      Parameters:
      htmlContent - the HTML content string
    • appendHtml

      public void appendHtml(String htmlContent)
      Append HTML content to the existing document.
      Parameters:
      htmlContent - the HTML content string to append
    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from class: OfficeDocument
      Gets the input stream.
      Specified by:
      getInputStream in class OfficeDocument
      Returns:
      the input stream
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getBytes

      public byte[] getBytes() throws IOException
      Description copied from class: OfficeDocument
      Gets the bytes.
      Specified by:
      getBytes in class OfficeDocument
      Returns:
      the bytes
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getFields

      public List<Field> getFields()
      Gets the fields.
      Returns:
      the fields
    • getSections

      public List<Section> getSections()
      Gets the sections.
      Returns:
      the sections
    • getTables

      public List<Table> getTables()
      Gets the tables.
      Returns:
      the tables
    • getParagraphs

      public List<Paragraph> getParagraphs()
      Gets the paragraphs.
      Returns:
      the paragraphs
    • getRuns

      public List<Run> getRuns()
      Gets the runs.
      Returns:
      the runs
    • getTexts

      public List<Text> getTexts()
      Gets the texts.
      Returns:
      the texts
    • getPictures

      public List<IPicture> getPictures()
      Gets the pictures.
      Returns:
      the pictures
    • replace

      public void replace(String oldText, String newText)
      Replace.
      Parameters:
      oldText - the old text
      newText - the new text
    • replace

      public void replace(String oldText, String newText, ReplaceIn replaceIn)
      Replace.
      Parameters:
      oldText - the old text
      newText - the new text
      replaceIn - the replace in
    • replace

      public void replace(List<String> oldText, List<String> newText)
      Replace.
      Parameters:
      oldText - the old text
      newText - the new text
    • replace

      public void replace(List<String> oldText, List<String> newText, ReplaceIn replaceIn)
      Replace.
      Parameters:
      oldText - the old text
      newText - the new text
      replaceIn - the replace in
    • replace

      public void replace(String text, Run run)
      Replace.
      Parameters:
      text - the text
      run - the run
    • replace

      public void replace(String text, Run run, ReplaceIn replaceIn)
      Replace.
      Parameters:
      text - the text
      run - the run
      replaceIn - the replace in
    • replace

      public void replace(String text, List<Run> runs)
      Replace.
      Parameters:
      text - the text
      runs - the runs
    • replace

      public void replace(String text, List<Run> runs, ReplaceIn replaceIn)
      Replace.
      Parameters:
      text - the text
      runs - the runs
      replaceIn - the replace in
    • getContentElements

      public List<IContentElement> getContentElements()
      Gets the content elements.
      Returns:
      the content elements
    • clone

      public WordDocument clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toText

      public String toText()
      To text.
      Returns:
      the string
    • isTemplate

      public boolean isTemplate()
      Checks if is template.
      Returns:
      true, if is template
    • setTemplate

      public void setTemplate(boolean isTemplate)
      Sets the template.
      Parameters:
      isTemplate - the new template
    • isMacroEnabled

      public boolean isMacroEnabled()
      Checks if is macro enabled.
      Returns:
      true, if is macro enabled
    • setMacroEnabled

      public void setMacroEnabled(boolean isMacroEnabled)
      Sets the macro enabled.
      Parameters:
      isMacroEnabled - the new macro enabled
    • getBody

      public Body getBody()
      Gets the body.
      Returns:
      the body
    • getMarkupCompatibilityIgnorable

      public String getMarkupCompatibilityIgnorable()
      Gets the mc:Ignorable attribute value of the document root, or null if absent.
      Returns:
      the markup-compatibility ignorable prefixes
    • setMarkupCompatibilityIgnorable

      public void setMarkupCompatibilityIgnorable(String markupCompatibilityIgnorable)
      Sets the mc:Ignorable attribute value of the document root.
      Parameters:
      markupCompatibilityIgnorable - the new value
    • getGlossaryDocument

      public GlossaryDocument getGlossaryDocument()
      Gets the glossary document.
      Returns:
      the glossary document
    • setGlossaryDocument

      public void setGlossaryDocument(GlossaryDocument glossaryDocument)
      Sets the glossary document.
      Parameters:
      glossaryDocument - the new glossary document
    • getBackground

      public Background getBackground()
      Gets the background.
      Returns:
      the background
    • setBackground

      public void setBackground(Background background)
      Sets the background.
      Parameters:
      background - the new background
    • getStyleDefinitions

      public StyleDefinitions getStyleDefinitions()
      Gets the style definitions.
      Returns:
      the style definitions
    • setStyleDefinitions

      public void setStyleDefinitions(StyleDefinitions styleDefinitions)
      Sets the style definitions.
      Parameters:
      styleDefinitions - the new style definitions
    • getNumberingDefinitions

      public NumberingDefinitions getNumberingDefinitions()
      Gets the numbering definitions.
      Returns:
      the numbering definitions
    • setNumberingDefinitions

      public void setNumberingDefinitions(NumberingDefinitions numberingDefinitions)
      Sets the numbering definitions.
      Parameters:
      numberingDefinitions - the new numbering definitions
    • getFonts

      public List<Font> getFonts()
      Gets the fonts.
      Returns:
      the fonts
    • getSettings

      public Settings getSettings()
      Gets the settings.
      Returns:
      the settings
    • getWebSettings

      public WebSettings getWebSettings()
      Gets the web settings.
      Returns:
      the web settings
    • getComments

      public List<Comment> getComments()
      Gets the comments.
      Returns:
      the comments
    • getFootnotes

      public List<Footnote> getFootnotes()
      Gets the footnotes.
      Returns:
      the footnotes
    • getEndnotes

      public List<Endnote> getEndnotes()
      Gets the endnotes.
      Returns:
      the endnotes
    • getFooterTable

      public HashMap<String,​Footer> getFooterTable()
      Gets the footer table.
      Returns:
      the footer table
    • getHeaderTable

      public HashMap<String,​Header> getHeaderTable()
      Gets the header table.
      Returns:
      the header table
    • getTheme

      public Theme getTheme()
      Gets the document theme.
      Overrides:
      getTheme in class OfficeDocument
      Returns:
      the theme