GithubHelp home page GithubHelp logo

docx2pdf-api's Introduction

Docx2PDF API

Overview

The Docx2PDF API is a FastAPI application designed to convert DOCX files to PDF format. It provides a simple and efficient way to handle file conversion in a web environment.

Features

  • File Conversion: Converts DOCX files to PDF.
  • REST API: Easy to integrate with other applications using HTTP requests.
  • Cross-Origin Resource Sharing (CORS): Configured to allow requests from any origin.
  • Asynchronous Handling: Processes file uploads and conversions asynchronously for better performance.

Requirements

  • Python 3.6 or higher
  • FastAPI
  • Uvicorn for running the server
  • LibreOffice installed on the server for file conversion

Installation

  1. Install the required Python packages:
    pip install fastapi uvicorn
  2. Ensure LibreOffice is installed on your server.

Usage

  1. Start the FastAPI server:
    uvicorn main:app --host 0.0.0.0 --port 8001
  2. Use the /convert/ endpoint to upload a DOCX file and receive a converted PDF in response.

Endpoint Details

  • URL: /convert/
  • Method: POST
  • Body:
    • doc_file: The DOCX file to be converted.

Example

import requests

url = 'http://localhost:8001/convert/'
files = {'doc_file': open('yourfile.docx', 'rb')}
response = requests.post(url, files=files)

with open('output.pdf', 'wb') as f:
    f.write(response.content)

Error Handling

  • The API handles file-related errors and ensures the temporary files are cleaned up after conversion.

Limitations

  • The API currently only supports DOCX to PDF conversion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.