pptxtodocument.mdx
1 --- 2 title: "PPTXToDocument" 3 id: pptxtodocument 4 slug: "/pptxtodocument" 5 description: "Convert PPTX files to documents." 6 --- 7 8 # PPTXToDocument 9 10 Convert PPTX files 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`: PPTX file paths or [`ByteStream`](../../concepts/data-classes.mdx#bytestream) objects | 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/pptx.py | 21 22 </div> 23 24 ## Overview 25 26 The `PPTXToDocument` component converts PPTX files into documents. 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 ## Usage 29 30 First, install the`python-pptx` package to start using this converter: 31 32 ```shell 33 pip install python-pptx 34 ``` 35 36 ### On its own 37 38 ```python 39 from haystack.components.converters import PPTXToDocument 40 41 converter = PPTXToDocument() 42 results = converter.run( 43 sources=["sample.pptx"], 44 meta={"date_added": datetime.now().isoformat()}, 45 ) 46 documents = results["documents"] 47 48 print(documents[0].content) 49 50 ## 'This is the text from the PPTX file.' 51 ``` 52 53 ### In a pipeline 54 55 ```python 56 from haystack import Pipeline 57 from haystack.document_stores.in_memory import InMemoryDocumentStore 58 from haystack.components.converters import PPTXToDocument 59 from haystack.components.preprocessors import DocumentCleaner 60 from haystack.components.preprocessors import DocumentSplitter 61 from haystack.components.writers import DocumentWriter 62 63 document_store = InMemoryDocumentStore() 64 65 pipeline = Pipeline() 66 pipeline.add_component("converter", PPTXToDocument()) 67 pipeline.add_component("cleaner", DocumentCleaner()) 68 pipeline.add_component( 69 "splitter", 70 DocumentSplitter(split_by="sentence", split_length=5), 71 ) 72 pipeline.add_component("writer", DocumentWriter(document_store=document_store)) 73 pipeline.connect("converter", "cleaner") 74 pipeline.connect("cleaner", "splitter") 75 pipeline.connect("splitter", "writer") 76 77 pipeline.run({"converter": {"sources": file_names}}) 78 ```