> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jinba.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Conversion Tools

> Convert data between different formats and structures

## Overview

Data Conversion Tools provide essential functionality for transforming data between different formats. These tools handle array-to-CSV conversion, image-to-PDF conversion, HTML-to-PDF/DOCX conversion, and other data transformation needs in your workflows.

## Key Features

### CONVERTER\_ARRAY\_TO\_CSV

* Convert 2D arrays to CSV format with automatic escaping
* Handles special characters (quotes, commas, newlines)
* Input: `input` (2D array) — Output: `result` (CSV string)
* Compatible with spreadsheet applications

### CONVERTER\_IMAGE\_TO\_PDF

* Convert images to PDF format
* Support for TIFF, PNG, JPEG, GIF, and more
* Input: `file_link` (array of image URLs, max 10 files)
* Output: `result` (URL of the generated PDF)

### CONVERTER\_HTML\_TO\_PDF

* Convert HTML content to a PDF file
* Input: `html_content` (HTML string), `filename` (optional, without extension)
* Output: `result` (signed URL to the created PDF file)

### CONVERTER\_HTML\_TO\_DOCX

* Convert HTML content to a DOCX (Word) file
* Input: `html_content` (HTML string), `filename` (optional, without extension)
* Output: `result` (signed URL to the created DOCX file)

## Authentication

No authentication required for conversion tools.

## Example: Data Export to CSV

```yaml theme={null}
- id: fetch_data
  name: fetch_data
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        # Sample data processing
        import json
        
        # Simulate fetching data from API or database
        raw_data = [
            {"name": "John Doe", "email": "john@example.com", "age": 30, "city": "New York"},
            {"name": "Jane Smith", "email": "jane@example.com", "age": 25, "city": "Los Angeles"},
            {"name": "Bob Johnson", "email": "bob@example.com", "age": 35, "city": "Chicago"}
        ]
        
        # Convert to 2D array format
        headers = ["Name", "Email", "Age", "City"]
        data_rows = []
        data_rows.append(headers)
        
        for item in raw_data:
            row = [item["name"], item["email"], str(item["age"]), item["city"]]
            data_rows.append(row)
        
        print(json.dumps(data_rows))

- id: convert_to_csv
  name: convert_to_csv
  tool: CONVERTER_ARRAY_TO_CSV
  input:
    - name: input
      value: "{{steps.fetch_data.result.stdout | fromJson}}"

- id: save_csv_file
  name: save_csv_file
  tool: OUTPUT_FILE
  input:
    - name: content
      value: "{{steps.convert_to_csv.result}}"
    - name: filename
      value: "user_data_export.csv"
    - name: fileType
      value: "csv"
```

## Example: Sales Report Generation

```yaml theme={null}
- id: calculate_sales_metrics
  name: calculate_sales_metrics
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        import json
        from datetime import datetime, timedelta
        
        # Sample sales data
        sales_data = [
            {"product": "Widget A", "sales": 1500, "region": "North", "month": "Jan"},
            {"product": "Widget B", "sales": 2300, "region": "South", "month": "Jan"},
            {"product": "Widget A", "sales": 1800, "region": "North", "month": "Feb"},
            {"product": "Widget B", "sales": 2100, "region": "South", "month": "Feb"}
        ]
        
        # Create summary table
        summary = [["Product", "Region", "Month", "Sales", "Growth"]]
        
        for i, item in enumerate(sales_data):
            growth = "N/A"
            if i >= 2:  # Calculate growth for Feb data
                prev_sales = sales_data[i-2]["sales"]
                growth = f"{((item['sales'] - prev_sales) / prev_sales * 100):.1f}%"
            
            summary.append([
                item["product"],
                item["region"], 
                item["month"],
                f"${item['sales']:,}",
                growth
            ])
        
        print(json.dumps(summary))

- id: export_sales_csv
  name: export_sales_csv
  tool: CONVERTER_ARRAY_TO_CSV
  input:
    - name: input
      value: "{{steps.calculate_sales_metrics.result.stdout | fromJson}}"

- id: create_downloadable_report
  name: create_downloadable_report
  tool: OUTPUT_FILE
  input:
    - name: content
      value: "{{steps.export_sales_csv.result}}"
    - name: filename
      value: "sales_report_{{date | format('YYYY-MM-DD')}}.csv"
    - name: fileType
      value: "csv"
```

## Example: Image to PDF Conversion

```yaml theme={null}
- id: input_images
  name: input_images
  tool: INPUT_IMAGE_FILE
  input:
    - name: file_url
      value: "https://example.com/chart1.png"
    - name: description
      value: "Sales chart image"

- id: convert_chart_to_pdf
  name: convert_chart_to_pdf
  tool: CONVERTER_IMAGE_TO_PDF
  input:
    - name: file_link
      value:
        - "https://example.com/chart1.png"

- id: convert_multiple_charts
  name: convert_multiple_charts
  tool: CONVERTER_IMAGE_TO_PDF
  input:
    - name: file_link
      value:
        - "https://example.com/chart1.png"
        - "https://example.com/chart2.png"
        - "https://example.com/chart3.png"
```

## Example: HTML to PDF / DOCX Conversion

```yaml theme={null}
- id: generate_html_report
  name: generate_html_report
  tool: OPENAI_INVOKE
  config:
    - name: version
      value: gpt-4
  input:
    - name: prompt
      value: |
        Generate an HTML report summarizing this month's sales results.
        Return only the HTML content.

- id: convert_report_to_pdf
  name: convert_report_to_pdf
  tool: CONVERTER_HTML_TO_PDF
  input:
    - name: html_content
      value: "{{steps.generate_html_report.result}}"
    - name: filename
      value: "monthly_sales_report"

- id: convert_report_to_docx
  name: convert_report_to_docx
  tool: CONVERTER_HTML_TO_DOCX
  input:
    - name: html_content
      value: "{{steps.generate_html_report.result}}"
    - name: filename
      value: "monthly_sales_report"

# steps.convert_report_to_pdf.result is a signed URL to the PDF file
# steps.convert_report_to_docx.result is a signed URL to the DOCX file
```

## Example: Complex Data Transformation

```yaml theme={null}
- id: extract_complex_data
  name: extract_complex_data
  tool: EXCEL_GET_ROWS
  input:
    - name: file_url
      value: "{{steps.input_excel.result.file_url}}"
    - name: range
      value: "A1:F1000"

- id: transform_and_clean_data
  name: transform_and_clean_data
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        import json
        import re
        
        # Parse the Excel data
        excel_data = {{steps.extract_complex_data.result.content}}
        
        # Clean and transform data
        cleaned_data = []
        headers = ["ID", "Name", "Email", "Phone", "Status", "Notes"]
        cleaned_data.append(headers)
        
        for row in excel_data[1:]:  # Skip header row
            if len(row) >= 6:
                # Clean email
                email = row[2].strip().lower() if row[2] else ""
                
                # Format phone number
                phone = re.sub(r'[^\d+]', '', row[3]) if row[3] else ""
                
                # Clean and escape notes (may contain commas, quotes)
                notes = str(row[5]).replace('"', '""') if row[5] else ""
                
                cleaned_row = [
                    str(row[0]) if row[0] else "",
                    str(row[1]).title() if row[1] else "",
                    email,
                    phone,
                    str(row[4]).upper() if row[4] else "PENDING",
                    notes
                ]
                cleaned_data.append(cleaned_row)
        
        print(json.dumps(cleaned_data))

- id: convert_cleaned_data
  name: convert_cleaned_data
  tool: CONVERTER_ARRAY_TO_CSV
  input:
    - name: input
      value: "{{steps.transform_and_clean_data.result.stdout | fromJson}}"

- id: save_cleaned_export
  name: save_cleaned_export
  tool: OUTPUT_FILE
  input:
    - name: content
      value: "{{steps.convert_cleaned_data.result}}"
    - name: filename
      value: "cleaned_data_export.csv"
    - name: fileType
      value: "csv"
```

## Data Format Support

### CSV Conversion

* **Input**: 2D arrays, JSON arrays, structured data
* **Output**: RFC 4180 compliant CSV
* **Features**: Automatic escaping, encoding handling

### Image to PDF

* **Supported formats**: TIFF, PNG, JPEG, GIF, and more
* **Input**: Up to 10 image URLs per conversion
* **Output**: PDF document URL

### HTML to PDF / DOCX

* **Input**: HTML content string and optional filename (without extension)
* **Output**: Signed URL to the generated PDF or DOCX file
* **Features**: Useful for turning LLM-generated HTML into downloadable documents

## Best Practices

### CSV Handling

* Always include headers in your data arrays
* Handle special characters (commas, quotes, newlines)
* Use consistent data types within columns
* Validate data before conversion

### Image Conversion

* Ensure images are accessible via public URLs
* Consider file size limitations
* Optimize images before conversion for better performance
* Use appropriate filenames for organization

## Use Cases

* **Data Export**: Export database queries to CSV for Excel
* **Report Generation**: Convert processed data to spreadsheet format
* **Document Creation**: Convert charts and images to PDF
* **Data Migration**: Transform data between different systems
* **Analytics Export**: Export analysis results for stakeholders
* **Backup and Archive**: Convert data to portable formats
* **Integration**: Prepare data for external system import
