How to convert Excel to PDF using Python

Table of contents

    Convert Excel files to PDF using Python and Nutrient DWS Processor API. This tutorial covers API setup, Python implementation, and document processing workflows for automating Excel-to-PDF conversion in your applications.
    How to convert Excel to PDF using Python
    Summary

    Convert Excel to PDF using Nutrient’s Python API. Create a free account, get API credentials, and implement conversion using the requests library. Combine with 30+ other API tools for merging, watermarking, and page manipulation.

    Convert Excel files to PDFs using Nutrient DWS Processor’s XLSX-to-PDF Python API. The free plan includes 200 credits. Different operations consume different amounts of credits. Create a free account(opens in a new tab) to get your API key.

    Why convert Excel to PDF?

    Converting Excel files to PDF is essential for workflows requiring document standardization and sharing. Common use cases include:

    • Document preservation — Convert spreadsheets to PDFs to preserve formatting, formulas, and layouts regardless of software or device used to view them.
    • Professional reporting — Generate polished financial reports, invoices, and data summaries that maintain consistent appearance across platforms.
    • Compliance and archiving — Create tamper-resistant records for auditing, regulatory compliance, and long-term document storage.
    • Universal sharing — Share data with stakeholders who don’t have Excel or prefer read-only formats that prevent accidental editing.
    • Print-ready documents — Ensure spreadsheets print exactly as intended without pagination or formatting issues.

    The Excel-to-PDF API automates this process in your workflow.

    Nutrient DWS Processor API

    Converting Excel-to-PDF is one of 30+ operations available through our PDF API tools. Combine Excel-to-PDF conversion with other tools for complex workflows:

    Your account includes access to all PDF API tools.

    Step 1 — Creating a free account on Nutrient DWS Processor

    Go to the signup page(opens in a new tab) to create your free account.

    Free account Nutrient DWS Processor API

    After account creation, the dashboard shows your plan details.

    You start with 200 credits and access to all PDF API tools.

    Step 2 — Obtaining the API key

    After email verification, get your API key from the dashboard. Click API keys in the left menu to see your keys.

    Convert Excel-to-PDF Python API Key

    Copy the Live API key for the Excel-to-PDF API.

    Step 3 — Setting up folders and files

    Create a folder called excel_to_pdf and open it in a code editor. This tutorial uses VS Code. Create two folders inside excel_to_pdf: input_documents and processed_documents.

    Copy your Excel file to the input_documents folder and rename it to document.xlsx. Use the demo document if needed.

    In the root folder, excel_to_pdf, create a file called processor.py for your code.

    Your folder structure will look like this:

    excel_to_pdf
    ├── input_documents
    | └── document.xlsx
    ├── processed_documents
    └── processor.py

    Step 4 — Writing the code

    Open the processor.py file and paste the code below into it:

    import requests
    import json
    response = requests.request(
    'POST',
    'https://api.nutrient.io/build',
    headers = {
    'Authorization': 'Bearer YOUR_API_KEY_HERE'
    },
    files = {
    'file': open('input_documents/document.xlsx', 'rb')
    },
    data = {
    'instructions': json.dumps({
    'parts': [
    {
    'file': 'file'
    }
    ]
    })
    },
    stream = True
    )
    if response.ok:
    with open('processed_documents/result.pdf', 'wb') as fd:
    for chunk in response.iter_content(chunk_size=8096):
    fd.write(chunk)
    else:
    print(response.text)
    exit()

    Make sure to replace YOUR_API_KEY_HERE with your API key.

    Code explanation

    The code imports the requests and json dependencies, and then creates the instructions for the API call.

    Use the requests module to make the API call. Once it succeeds, the result is saved to the processed_documents folder.

    Output

    Run the code:

    Terminal window
    python3 processor.py

    After execution, you’ll find result.pdf in the processed_documents folder.

    The folder structure will look like this:

    excel_to_pdf
    ├── input_documents
    | └── document.xlsx
    ├── processed_documents
    | └── result.pdf
    └── processor.py

    Additional resources

    Explore more ways to work with Nutrient API:

    Conclusion

    This post covered converting Excel files to PDF documents using the Python API.

    Integrate these functions into your existing applications. The same API token works for other operations like merging documents, adding watermarks, and more. Sign up(opens in a new tab) for a free trial.

    FAQ

    Do I need a paid account to use Nutrient DWS Processor API?

    No. Start with a free account that provides 200 credits for processing documents. Different operations consume different amounts of credits, so you can process varying numbers of documents depending on the operations you use.

    Does Nutrient DWS Processor API preserve Excel formatting when converting to PDF?

    Yes. Nutrient DWS Processor API maintains spreadsheet formatting, including fonts, colors, cell borders, and merged cells. Complex formulas are calculated and displayed as values in the PDF output.

    Does Nutrient provide a Python client library for easier integration?

    Yes. The Nutrient Python client provides a higher-level interface for Nutrient DWS Processor API operations. While this tutorial uses direct HTTP requests with the requests library for transparency, the Python client simplifies authentication, error handling, and response parsing for production applications.

    Can I convert multi-sheet Excel workbooks to PDF?

    Yes. Nutrient DWS Processor API converts all sheets in an Excel workbook to a single PDF document, with each sheet appearing as a separate page or set of pages depending on the sheet size.

    Jonathan D. Rhyne

    Jonathan D. Rhyne

    Co-Founder and CEO

    Jonathan joined PSPDFKit in 2014. As Co-founder and CEO, Jonathan defines the company’s vision and strategic goals, bolsters the team culture, and steers product direction. When he’s not working, he enjoys being a dad, photography, and soccer.

    Explore related topics

    FREE TRIAL Ready to get started?