tikadocumentconverter.mdx
 1  ---
 2  title: "TikaDocumentConverter"
 3  id: tikadocumentconverter
 4  slug: "/tikadocumentconverter"
 5  description: "An integration for converting files of different types (PDF, DOCX, HTML, and more) to documents."
 6  ---
 7  
 8  # TikaDocumentConverter
 9  
10  An integration for converting files of different types (PDF, DOCX, HTML, and more) to documents.
11  
12  <div className="key-value-table">
13  
14  |  |  |
15  | --- | --- |
16  | **Most common position in a pipeline** | Before [PreProcessors](../preprocessors.mdx) , or right at the beginning of an indexing pipeline |
17  | **Mandatory run variables**            | `sources`: File paths                                                                           |
18  | **Output variables**                   | `documents`: A list of documents                                                                |
19  | **API reference**                      | [Converters](/reference/converters-api)                                                                |
20  | **GitHub link**                        | https://github.com/deepset-ai/haystack/blob/main/haystack/components/converters/tika.py       |
21  
22  </div>
23  
24  ## Overview
25  
26  The `TikaDocumentConverter` component converts files of different types (pdf, docx, html, and others) into documents. You can use it in an indexing pipeline to index the contents of files into a Document Store. It takes a list of file paths or [`ByteStream`](../../concepts/data-classes.mdx#bytestream) objects as input and outputs the converted result as a list of documents. Optionally, you can attach metadata to the documents through the `meta` input parameter.
27  
28  This integration uses [Apache Tika](https://tika.apache.org/) to parse the files and requires a running Tika server.
29  
30  The easiest way to run Tika is by using Docker: `docker run -d -p 127.0.0.1:9998:9998 apache/tika:latest`.
31  For more options on running Tika on Docker, see the [Tika documentation](https://github.com/apache/tika-docker/blob/main/README.md#usage).
32  
33  When you initialize the `TikaDocumentConverter` component, you can specify a custom URL of the Tika server you are using through the parameter `tika_url`. The default URL is `"http://localhost:9998/tika"`.
34  
35  ## Usage
36  
37  You need to install `tika` package to use the `TikaDocumentConverter` component:
38  
39  ```shell
40  pip install tika
41  ```
42  
43  ### On its own
44  
45  ```python
46  from haystack.components.converters import TikaDocumentConverter
47  from pathlib import Path
48  
49  converter = TikaDocumentConverter()
50  
51  converter.run(sources=[Path("my_file.pdf")])
52  ```
53  
54  ### In a pipeline
55  
56  ```python
57  from haystack import Pipeline
58  from haystack.document_stores.in_memory import InMemoryDocumentStore
59  from haystack.components.converters import TikaDocumentConverter
60  from haystack.components.preprocessors import DocumentCleaner
61  from haystack.components.preprocessors import DocumentSplitter
62  from haystack.components.writers import DocumentWriter
63  
64  document_store = InMemoryDocumentStore()
65  
66  pipeline = Pipeline()
67  pipeline.add_component("converter", TikaDocumentConverter())
68  pipeline.add_component("cleaner", DocumentCleaner())
69  pipeline.add_component(
70      "splitter",
71      DocumentSplitter(split_by="sentence", split_length=5),
72  )
73  pipeline.add_component("writer", DocumentWriter(document_store=document_store))
74  pipeline.connect("converter", "cleaner")
75  pipeline.connect("cleaner", "splitter")
76  pipeline.connect("splitter", "writer")
77  
78  pipeline.run({"converter": {"sources": file_paths}})
79  ```