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

# Excel To PDF

> Convert XLSX workbooks into PDF.

## Notes

* Credits: `2`
* Only `.xlsx` is supported
* Authenticated uploads are limited to `100 MB`
* Corrupted or renamed workbooks are rejected
* The generated output file name is `excel.pdf`


## OpenAPI

````yaml /openapi.json post /convert/excel-to-pdf
openapi: 3.0.3
info:
  title: IyzPdf Client API
  version: 1.0.0
  description: Client-facing document conversion and PDF editing endpoints for IyzPdf.
servers:
  - url: https://api.iyzpdf.com/v1
security:
  - ApiKeyAuth: []
tags:
  - name: Conversion
  - name: PDF Editing
paths:
  /convert/excel-to-pdf:
    post:
      tags:
        - Conversion
      summary: Convert an Excel workbook into PDF
      operationId: excelToPdf
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                  description: .xlsx workbook upload.
              required:
                - file
            examples:
              workbook:
                summary: XLSX upload
                value:
                  file: (binary)
      responses:
        '200':
          description: Successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BinaryFileMetadataResponse'
              example:
                fileName: excel.pdf
                size: 240883
                creditsUsed: 2
                creditsRemaining: 48
                contentType: application/pdf
            application/pdf:
              schema:
                type: string
                format: binary
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      x-codeSamples:
        - label: curl
          lang: bash
          source: |-
            curl --request POST \
              --url https://api.iyzpdf.com/v1/convert/excel-to-pdf \
              --header "X-API-Key: $IYZPDF_API_KEY" \
              --form "file=@forecast.xlsx" \
              --output forecast.pdf
        - label: python
          lang: python
          source: |-
            import os
            import requests

            api_key = os.environ["IYZPDF_API_KEY"]

            with open("forecast.xlsx", "rb") as file_handle:
                response = requests.post(
                    "https://api.iyzpdf.com/v1/convert/excel-to-pdf",
                    headers={"X-API-Key": api_key},
                    files={
                        "file": (
                            "forecast.xlsx",
                            file_handle,
                            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        )
                    },
                    timeout=60,
                )

            if not response.ok:
                raise Exception(response.text)

            with open("forecast.pdf", "wb") as output_file:
                output_file.write(response.content)
        - label: javascript
          lang: javascript
          source: >-
            import { readFileSync } from "node:fs";

            import { writeFile } from "node:fs/promises";


            const apiKey = process.env.IYZPDF_API_KEY;

            const form = new FormData();


            form.append(
              "file",
              new Blob([readFileSync("forecast.xlsx")], {
                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
              }),
              "forecast.xlsx"
            );


            const response = await
            fetch("https://api.iyzpdf.com/v1/convert/excel-to-pdf", {
              method: "POST",
              headers: {
                "X-API-Key": apiKey
              },
              body: form
            });


            if (!response.ok) {
              throw new Error(await response.text());
            }


            await writeFile("forecast.pdf", Buffer.from(await
            response.arrayBuffer()));
        - label: php
          lang: php
          source: |-
            <?php

            $apiKey = getenv('IYZPDF_API_KEY');

            $ch = curl_init('https://api.iyzpdf.com/v1/convert/excel-to-pdf');

            curl_setopt_array($ch, [
                CURLOPT_POST => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HTTPHEADER => [
                    'X-API-Key: ' . $apiKey,
                ],
                CURLOPT_POSTFIELDS => [
                    'file' => new CURLFile('forecast.xlsx'),
                ],
            ]);

            $pdf = curl_exec($ch);
            $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            if ($pdf === false || $status !== 200) {
                throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $pdf);
            }

            file_put_contents('forecast.pdf', $pdf);
            curl_close($ch);
        - label: java
          lang: java
          source: |-
            import java.io.IOException;
            import java.nio.file.Files;
            import java.nio.file.Path;
            import okhttp3.MediaType;
            import okhttp3.MultipartBody;
            import okhttp3.OkHttpClient;
            import okhttp3.Request;
            import okhttp3.RequestBody;
            import okhttp3.Response;

            public class ExcelToPdfExample {
                public static void main(String[] args) throws IOException {
                    String apiKey = System.getenv("IYZPDF_API_KEY");
                    OkHttpClient client = new OkHttpClient();

                    RequestBody formBody = new MultipartBody.Builder()
                        .setType(MultipartBody.FORM)
                        .addFormDataPart(
                            "file",
                            "forecast.xlsx",
                            RequestBody.create(
                                Files.readAllBytes(Path.of("forecast.xlsx")),
                                MediaType.parse("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")))
                        .build();

                    Request request = new Request.Builder()
                        .url("https://api.iyzpdf.com/v1/convert/excel-to-pdf")
                        .addHeader("X-API-Key", apiKey)
                        .post(formBody)
                        .build();

                    try (Response response = client.newCall(request).execute()) {
                        if (!response.isSuccessful() || response.body() == null) {
                            String errorBody = response.body() != null ? response.body().string() : "";
                            throw new IOException("Request failed: " + response.code() + " " + errorBody);
                        }

                        Files.write(Path.of("forecast.pdf"), response.body().bytes());
                    }
                }
            }
        - label: c#
          lang: csharp
          source: |-
            var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
            using var client = new HttpClient();
            using var form = new MultipartFormDataContent();
            await using var fileStream = File.OpenRead("forecast.xlsx");

            client.DefaultRequestHeaders.Add("X-API-Key", apiKey);

            form.Add(new StreamContent(fileStream), "file", "forecast.xlsx");

            using var response = await client.PostAsync(
                "https://api.iyzpdf.com/v1/convert/excel-to-pdf",
                form);

            response.EnsureSuccessStatusCode();

            await using var output = File.Create("forecast.pdf");
            await response.Content.CopyToAsync(output);
components:
  schemas:
    BinaryFileMetadataResponse:
      type: object
      properties:
        fileName:
          type: string
        size:
          type: integer
          format: int32
        creditsUsed:
          type: integer
          format: int32
        creditsRemaining:
          type: integer
          format: int32
          nullable: true
        contentType:
          type: string
      required:
        - fileName
        - size
        - creditsUsed
        - contentType
      example:
        fileName: output.pdf
        size: 183240
        creditsUsed: 1
        creditsRemaining: 49
        contentType: application/pdf
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            creditsRequired:
              type: integer
              format: int32
              nullable: true
            creditsBalance:
              type: integer
              format: int32
              nullable: true
            purchaseUrl:
              type: string
              nullable: true
          required:
            - code
            - message
      required:
        - error
      example:
        error:
          code: INVALID_REQUEST
          message: The request payload is invalid or incomplete.
  responses:
    BadRequest:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INVALID_REQUEST
              message: The request payload is invalid or incomplete.
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNAUTHORIZED
              message: Missing or invalid API key.
    PaymentRequired:
      description: Insufficient credits
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INSUFFICIENT_CREDITS
              message: You need more credits to complete this request.
              creditsRequired: 2
              creditsBalance: 0
              purchaseUrl: https://iyzpdf.com/portal/credits
    PayloadTooLarge:
      description: Payload too large
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: FILE_TOO_LARGE
              message: >-
                The uploaded file or request body exceeds the allowed size
                limit.
    UnsupportedMediaType:
      description: Unsupported media type
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNSUPPORTED_MEDIA_TYPE
              message: The uploaded file type or content type is not supported.
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: RATE_LIMIT_EXCEEDED
              message: Too many requests. Please retry after the rate limit resets.
    InternalError:
      description: Processing failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: PROCESSING_FAILED
              message: The document could not be processed.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Send your server-side API key in the X-API-Key header.

````