# Generate Output in Different Format Save documents assembled in Python in a different format than the template (DOCX to PDF, DOCX to HTML, XLSX to PDF), by file extension or with LoadSaveOptions. ## Overview GroupDocs.Assembly for Python via .NET allows you to generate output documents in a different format than the template. For example, you can create a DOCX template but output a PDF, or create an XLSX template but output a PDF. With file paths, the output format is determined by the file extension of the output path; with streams, [LoadSaveOptions](https://reference.groupdocs.com/assembly/python-net/groupdocs.assembly/loadsaveoptions/) names it. The main class involved is: - [DocumentAssembler](https://reference.groupdocs.com/assembly/python-net/groupdocs.assembly/documentassembler/) - assembles documents and converts to output format Here are the steps to generate output in a different format: * Create a template document in one format (e.g., DOCX) * Specify an output path with a different file extension (e.g., .pdf, .html) * Assemble the document using DocumentAssembler * The output will be automatically converted to the specified format {{< alert style="info" >}} Format conversion is automatic based on the output file extension. Supported conversions depend on the template format - Word templates can convert to PDF, HTML, and more, while spreadsheet templates have more limited conversion options. {{< /alert >}} ## Convert DOCX Template to PDF Generate a PDF from a Word template: {{< tabs "example1" >}} {{< tab "Python" >}} ```python from datetime import datetime from decimal import Decimal from groupdocs.assembly import DataSourceInfo, DocumentAssembler # DOCX template, PDF output template_path = "customer-invoice.docx" output_path = "customer-invoice-report.pdf" invoice_data = { "CustomerName": "Quayside Bistro", "Amount": Decimal("552.00"), "Date": datetime(2015, 1, 14), } assembler = DocumentAssembler() assembler.assemble_document(template_path, output_path, DataSourceInfo(invoice_data, "invoice")) print("PDF generated from DOCX template.") ``` {{< /tab >}} {{< tab "customer-invoice.docx" >}} {{< tab-text >}} The following sample file is used in this example: [customer-invoice.docx](https://docs.groupdocs.com/assembly/python-net/_sample_files/developer-guide/basic-usage/different-format-output/customer-invoice.docx) {{< /tab-text >}} {{< /tab >}} {{< tab "customer-invoice-report.pdf" >}} ```text Binary file (PDF, 20 KB) ``` [Download full output](https://docs.groupdocs.com/assembly/python-net/_output_files/developer-guide/basic-usage/different-format-output/convert_docx_template_to_pdf/customer-invoice-report.pdf) {{< /tab >}} {{< /tabs >}} ## Convert DOCX Template to HTML Generate an HTML file from a Word template: {{< tabs "example2" >}} {{< tab "Python" >}} ```python from groupdocs.assembly import DataSourceInfo, DocumentAssembler # DOCX template, HTML output template_path = "monthly-report.docx" output_path = "monthly-report-report.html" report_data = { "Title": "Monthly Report", "Month": "January 2015", } assembler = DocumentAssembler() assembler.assemble_document(template_path, output_path, DataSourceInfo(report_data, "report")) print("HTML generated from DOCX template.") ``` {{< /tab >}} {{< tab "monthly-report.docx" >}} {{< tab-text >}} The following sample file is used in this example: [monthly-report.docx](https://docs.groupdocs.com/assembly/python-net/_sample_files/developer-guide/basic-usage/different-format-output/monthly-report.docx) {{< /tab-text >}} {{< /tab >}} {{< tab "monthly-report-report.html" >}} ```text
}}
{{< tab "Python" >}}
```python
from groupdocs.assembly import DataSourceInfo, DocumentAssembler
# DOCX template, XPS output
template_path = "price-notice.docx"
output_path = "price-notice-report.xps"
document_data = {
"Title": "Price Notice",
"Content": "From 1 March 2015, Chestnut honey is 7.80 per jar.",
}
assembler = DocumentAssembler()
assembler.assemble_document(template_path, output_path, DataSourceInfo(document_data, "document"))
print("XPS generated from DOCX template.")
```
{{< /tab >}}
{{< tab "price-notice.docx" >}}
{{< tab-text >}}
The following sample file is used in this example: [price-notice.docx](https://docs.groupdocs.com/assembly/python-net/_sample_files/developer-guide/basic-usage/different-format-output/price-notice.docx)
{{< /tab-text >}}
{{< /tab >}}
{{< tab "price-notice-report.xps" >}}
```text
Binary file (XPS, 50 KB)
```
[Download full output](https://docs.groupdocs.com/assembly/python-net/_output_files/developer-guide/basic-usage/different-format-output/convert_docx_template_to_xps/price-notice-report.xps)
{{< /tab >}}
{{< /tabs >}}
## Convert XLSX Template to PDF
Generate a PDF from an Excel template:
{{< tabs "example4" >}}
{{< tab "Python" >}}
```python
from groupdocs.assembly import DataSourceInfo, DocumentAssembler
# XLSX template, PDF output
template_path = "sales-summary.xlsx"
output_path = "sales-summary-report.pdf"
data = {
"ReportTitle": "Sales Report",
"Quarter": "Q1 2015",
}
assembler = DocumentAssembler()
assembler.assemble_document(template_path, output_path, DataSourceInfo(data, "report"))
print("PDF generated from XLSX template.")
```
{{< /tab >}}
{{< tab "sales-summary.xlsx" >}}
{{< tab-text >}}
The following sample file is used in this example: [sales-summary.xlsx](https://docs.groupdocs.com/assembly/python-net/_sample_files/developer-guide/basic-usage/different-format-output/sales-summary.xlsx)
{{< /tab-text >}}
{{< /tab >}}
{{< tab "sales-summary-report.pdf" >}}
```text
Binary file (PDF, 32 KB)
```
[Download full output](https://docs.groupdocs.com/assembly/python-net/_output_files/developer-guide/basic-usage/different-format-output/convert_xlsx_template_to_pdf/sales-summary-report.pdf)
{{< /tab >}}
{{< /tabs >}}
## Convert PPTX Template to PDF
Generate a PDF from a PowerPoint template:
{{< tabs "example5" >}}
{{< tab "Python" >}}
```python
from groupdocs.assembly import DataSourceInfo, DocumentAssembler
# PPTX template, PDF output
template_path = "quarterly-slides.pptx"
output_path = "quarterly-slides-report.pdf"
presentation_data = {
"Title": "Quarterly Review",
"Quarter": "Q1 2015",
}
assembler = DocumentAssembler()
assembler.assemble_document(template_path, output_path, DataSourceInfo(presentation_data, "presentation"))
print("PDF generated from PPTX template.")
```
{{< /tab >}}
{{< tab "quarterly-slides.pptx" >}}
{{< tab-text >}}
The following sample file is used in this example: [quarterly-slides.pptx](https://docs.groupdocs.com/assembly/python-net/_sample_files/developer-guide/basic-usage/different-format-output/quarterly-slides.pptx)
{{< /tab-text >}}
{{< /tab >}}
{{< tab "quarterly-slides-report.pdf" >}}
```text
Binary file (PDF, 28 KB)
```
[Download full output](https://docs.groupdocs.com/assembly/python-net/_output_files/developer-guide/basic-usage/different-format-output/convert_pptx_template_to_pdf/quarterly-slides-report.pdf)
{{< /tab >}}
{{< /tabs >}}
## Convert Email Template to PDF
Generate a PDF from an email template (an EML message here; an MSG template works the same way):
{{< tabs "example6" >}}
{{< tab "Python" >}}
```python
from groupdocs.assembly import DataSourceInfo, DocumentAssembler
# EML template, PDF output
template_path = "invoice-notice.eml"
output_path = "invoice-notice-report.pdf"
email_data = {
"Recipient": "Quayside Bistro