Coder Social home page Coder Social logo

docx-to-pdf's Introduction

Docx to PDF converter

The problem: too many tools to convert from docx to PDF, but usually they end up messing something up in the formating, handling RTL text, handling different fonts and so on. This library is built right on top of LibreOffice, and provides an HTTP API that allows uploading a *.docx file and respondes with the *.pdf file back.

Usage

You will need docker and docker compose to run this tool.

# In the root of this repositry after cloning
$ docker-compose up -d --build

After building the image and upping the container, you can inspect the logs by running

docker-compose logs -tf --tail=100 pdf_generator

The api will be exposed at localhost:9999/docx-to-pdf

Example Request (cURL)

curl --location --request POST 'http://localhost:9999/docx-to-pdf' \
--form 'document=@"/C:/contract.docx"'

Example Request (JavaScript)

const formdata = new FormData();
formdata.append("document", fileInput.files[0], "/C:/contract.docx");

const requestOptions = {
  method: 'POST',
  body: formdata,
  redirect: 'follow'
};

fetch("http://localhost:9999/docx-to-pdf", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Response

A pdf file (application/pdf)

FAQ

  • The generated PDF fonts are not proper, what went wrong?

Most probably the font you are using is not included within the build, you will need to add your custom fonts within the ./fonts folder directly (both ttf and otf should work)

  • Some shapes are not in their place, why is this happening?

Sadly, this is an artifact from LibreOffice, you might want to make your shapes to be inline (following text) and not floating around as a workaround.

License

MIT License

Author

Mohammed Alhaddar

docx-to-pdf's People

Contributors

moalhaddar avatar

Watchers

 avatar

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.