Giter Site home page Giter Site logo

eugenmayer / officeconverter Goto Github PK

View Code? Open in Web Editor NEW
72.0 6.0 26.0 552 KB

Convert file formats like docx, xlx to other formats like pdf, png - based on jodconverter and libreoffice

License: Other

Dockerfile 11.55% Makefile 6.49% Shell 3.06% Kotlin 78.90%
libreoffice jodconverter office converter pdf

officeconverter's Introduction

tests docker publish

WAT

Offers a (i think production ready) REST service to convert files like PDF, docx,xlx .. odt .. you get it.. to other formats like pdf, png, doc, pdt, html. This project is basically an extended version of jodconverter-samples-rest

You can use this project as it is using docker with ghcr.io/eugenmayer/kontextwork-converter or build it here yourself.

Usage

docker run --memory 512m --name converter-prod --rm -p 8080:8080 ghcr.io/eugenmayer/kontextwork-converter:production

Now convert a docx to html

cd officeconverter
curl -F file=@src/test/resources/testfiles/withpictures.docx "localhost:14080/conversion?format=html" -o /tmp/test.html
curl -F file=@src/test/resources/testfiles/template.dotx "localhost:14080/conversion?format=html" -o /tmp/test.html

REST endpoints

Check the controller to understand the different endpoints

  • /conversion?format=html as multipart with file as the file to convert and format for the target format

Configuration

You can configure the docker images by mounting /etc/app/application.yml and put whatever you like into them.

For example if you like to have 2 LibreOffice instances, you would put into the file

# amount of libreOffice instances to start - one for each given port. So this means 2
jodconverter:
  local:
    port-numbers: 
      - 2002
      - 2003
    # change the tmp folder
    working-dir: /tmp
# change upload sizes
spring:
  servlet:
    multipart:
      max-file-size: 5MB
      max-request-size: 5MB
# change the server port (where the REST app is listenting)
server:
    portL: 8090

Adding addition document formats

You can edit the src/resources/document-formats.json and add new custom formats. The original can be found at (https://github.com/jodconverter/jodconverter/blob/master/jodconverter-core/src/main/resources/document-formats.json)[jodconverter-core].

We already added support for dotx/xltx for example.

Build

local java build, when you have all the build tools present + libreoffice locally installed

./gradlew build
# you find the artifact in /tmp/gradle-officeconverter/builds/libs/officeconverter-*.jar
# the jar file is a full tomcat bundled app, so just start it like that
java -jar /tmp/gradle-officeconverter/build/libs/officeconverter-*.jar

or better use the docker image with everything included, no dev tools/LO needed locally

# this builds the source a
make build
make start-prod

You can now connect to the 5001 remote debugger port, just use the existing IntelliJ task if you like

Tests

You can run the tests locally (you will need libreoffice installed)

./gradlew itTests

Or run the test in the docker-container

make test

Development

You can either use the IDE task or the local gradle

./gradlew -Pdev bootRun

Or even better, use the development container. You will not need any LibreOffice/Gradle installed locally

 make start-src # basically just docker-compose up

This fires up a docker container, mounts your source. To auto-rebuild and auto-restart he app very quick do this

 make watch
 # or just run ./watch.sh localy

Debugging

Of course, you can just start using your IDE and debug that, but if you want to debug inside the docker container

make start

And now connect(attach) to localhost 5001 for debugging ghcr.io/eugenmayer/kontextwork-converter:development has a default remote debugging port enabled on 5001

Release

CI based on tags

Upgrade

To upgrade libreoffice or the jodconverter runtime

  • see available releases under https://github.com/jodconverter/docker-image-jodconverter-runtime
  • create pr and adjust .github/docker-pr.yml and .github/docker-pr.yml RUNTIME_VERSION to match your version
  • Update the RUNTIME_VERSION in the makefile
  • run make test and ensure the test run inside the docker container (against the pre-build libre office and the JDK version)
  • merge PR if tests run successfully

Internals

  • state of the art springboot 3.0 application exposing a classic rest service to convert office document
  • using jodconverter-spring-boot-starter for wiring jodconverter-local services
  • build on/for Java 17 for better Docker support

Warranty

Absolutely none, use it at your own risk and without any guarantees.

Credits

A lot of credits go to jodconverter by jodconverter - we completely base on his work. Cheer him up!

officeconverter's People

Contributors

dependabot-preview[bot] avatar eugenmayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

officeconverter's Issues

Error creating bean with name 'localOfficeManager' defined in class path resource

I am building this application on the windows machine and installed the LibreOffice locally from https://www.libreoffice.org/download/download/ link.

image

Build Successful, but when I am running jar this error is coming

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'converterService' defined in URL [jar:file:/E:/repos/Github/officeconverter/tmp/gradle-officeconverter/build/libs/officeconverter-unspecified.jar!/BOOT-INF/classes!/de/kontextwork/converter/service/ConverterService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'localOfficeManager' defined in class path resource [org/jodconverter/boot/autoconfigure/JodConverterLocalAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jodconverter.core.office.OfficeManager]: Factory method 'localOfficeManager' threw exception; nested exception is java.lang.NullPointerException

Build Docker

As the title says, if I build with Docker it is
docker run --memory 512m --name converter-prod --rm -p 8080:8080 ghcr.io/eugenmayer/kontextwork-converter:production

then by default, I just need to change the file path in

curl -F file=@src/test/resources/testfiles/withpictures.docx "localhost:14080/conversion?format=html" -o /tmp/test.html
curl -F file=@src/test/resources/testfiles/template.dotx "localhost:14080/conversion?format=html" -o /tmp/test.html```

should work fine, right?

Lost contents when convert to image

I just want to convert (doc/docx/xls/xlsx .etc)to image and only get the preview of it.(only first page)

but convert to pdf right.

What should I do?

Which License

Hello,

I just saw your project but I can find any license on it, could you please share the license that you will/want to put on this project?

best regards

Swagger docs not reachable

Hi, the URL localhost:8080/swagger-ui.html doesnt work in the Docker box, it gives back a "whitelabel 404" error.

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.