Coder Social home page Coder Social logo

libreconv's Introduction

Libreconv

Convert office documents using LibreOffice / OpenOffice to one of their supported formats.

Build Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'libreconv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install libreconv

Usage

You need to install LibreOffice or OpenOffice on your system to use this gem. The code has been tested with LibreOffice 6.1.3.

require 'libreconv'

# Converts document.docx to my_document_as.pdf
# This requires that the soffice binary is present in your PATH.
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf')

# Converts document.docx to pdf and writes the output to the specified path
# This requires that the soffice binary is present in your PATH.
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')

# You can also convert a source file directly from an URL
Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents/doc.pdf')

# You cal pass a URL with GET params like this S3 example
Libreconv.convert('https://mybucket.s3.amazonaws.com/myserver/123/document.docx?X-Amz-Expires=456&X-Amz-Signature=abc', '/Users/ricn/pdf_documents/doc.pdf')

# Converts document.docx to document.pdf
# If you for some reason can't have soffice in your PATH you can specify the file path to the soffice binary
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents', '/Applications/LibreOffice.app/Contents/MacOS/soffice')

# Converts document.docx to my_document_as.html
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.html', nil, 'html')

# Converts document.docx to my_document_as.pdf using writer_pdf_Export filter
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf', nil, 'pdf:writer_pdf_Export')

Development

After checking out the repo, run bundle install to install dependencies. Then, run bundle exec rake to run the tests. You can also run irb -r bundler/setup -r libreconv for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

  • Install LibreOffice on Linux: sudo apt-get install libreoffice
  • Install LibreOffice on Mac: brew cask install libreoffice
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

The following people have contributed ideas, documentation, or code to Libreconv:

License

The gem is available as open source under the terms of the MIT License.

libreconv's People

Contributors

bfcoder avatar daneshd avatar gingermusketeer avatar ndbroadbent avatar nthachus avatar ricn avatar steimel 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  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  avatar  avatar  avatar  avatar  avatar  avatar

libreconv's Issues

Errno::ENOENT (No such file or directory @ rb_file_s_stat - /tmp/sample_template.pdf)

I am using the following command:

Libreconv.convert(doc.docx, mypdf.pdf, soffice_path)

It has a docx file as first argument, a pdf file as second argument and the path to soffice -> /opt/libreoffice4.4/program/soffice. When I try to run this statement in production, I get the following error;

Errno::ENOENT (No such file or directory @ rb_file_s_stat - /tmp/sample_template.pdf):
libreconv (0.9.0) lib/libreconv.rb:36:in convert' libreconv (0.9.0) lib/libreconv.rb:10:inconvert'

How can I resolve this? And if it is the version of libreoffice that is causing this, what version should I use for this gem?

getting error No such file or directory @ rb_file_s_stat - /tmp/test.docx

After upgrading the LibreOffice 4.2.8.2 420m0(Build:2) to LibreOffice 5.1.3.2 10m0(Build:2), I am suddenly getting error during docx conversion using the following command..
Libreconv.convert("test.html", "test.docx", ClockworkConfiguration.libreoffice.path, "docx")

I have the /tmp folder also have permission to write on it. Also I had closed all open instances of libreoffice.

How can I resolve this? And if it is the version of libreoffice that is causing this, what latest version should I use for this gem?

Feature request: Allows to set maximum acceptable conversion time, then timeout

Hello.

Sometimes our conversions run for a very long time without throwing any errors, it might be a corrupt file or something else happening. Would it be possible to allow the call to throw an error after a set time?

I tried to investigate if the soffice has this option but I have not been able to find out yet.

Thankful for any help and I could contribute if I am given some pointers.

New release on rubygems?

Hi there,

Do you know when / if there will be a new release on rubygems with the latest updates?

No such file or directory @ rb_sysopen

I am getting following error while convert the simple ms word document to pdf:

2.2.0 > Libreconv.convert('sample1.doc', '/Users/rp/test_document.pdf')

Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/sample1.pdf
from /home/rp/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/fileutils.rb:1391:in `initialize'

Gemfile in rubygems differs from the code in the repository

The code in the rubygems seems to be older:

    def convert
      orig_stdout = $stdout.clone
      $stdout.reopen File.new('/dev/null', 'w')
      pid = Spoon.spawnp(@soffice_command, "--headless", "--convert-to", @convert_to, @source, "--outdir", @target_path)
      Process.waitpid(pid)
      $stdout.reopen orig_stdout
      target_tmp_file = "#{@target_path}/#{File.basename(@source, ".*")}.#{File.basename(@convert_to, ":*")}"
      FileUtils.cp target_tmp_file, @target
    end

The package released in the release section also has this same code.

encode error

generate pdf success but content encode error

image

image

how to fix this bug?

Does it work on Windows?

Hi guys.
Does the gem work on Windows?
I have tried with both OpenOffice and LibreOffice but unfortunately I got only errors 😞

Custom fonts into the generated PDF

Hello

Thank you for this great gem, I really appreciate it

I'm converting a docx file to PDF using libreconv and I want to keep the same fonts that I'm using inside the docx file but the generated PDF does not have the same fonts

What is the solution for this issue?

Convert xlsb to xlsx file with password fails

Hi I'm trying to convert a xlsb to xlsx file however the xlsb file has password, with this files I get this issue

[3] pry(main)> Libreconv.convert('/Users/joelgarcia/Downloads/InsightReports_CM.xlsb', '/Users/joelgarcia/Downloads/InsightReports_CM.xlsx')
Libreconv::ConversionFailedError: Conversion failed! Output: "", Error: "Error: source file could not be loaded"

someone know how can I solved it?

Anybody running into can't find java error on heroku?

Conversion failed! Output: "", Error: "javaldx: Could not find a Java Runtime Environment!\nWarning: failed to read path from javaldx

I'm getting the above error intermittently. It usually isn't a problem, but sometimes I get the error above during conversion from DOCX to HTML.

Fail convert if "convert_to" consists of three parts

To convert a document to HTML with embdedded images, you must use convert_to param 'html:HTML:EmbedImages'.
For example:
Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.html', nil, 'html:HTML:EmbedImages')

But this code fail at

target_tmp_file = File.join(
          target_path,
          File.basename(@escaped_source_path, '.*') + '.' +
            File.basename(@convert_to, ':*')
        )

because generating output filename extension File.basename(@convert_to, ':*') returns 'html:HTML'.
This is incorrect filename extension.

I think code
File.basename(@convert_to, ':*')
must be replaced by something like this
@convert_to.split(':').first

Getting 403 Forbidden when using S3 url

I've noticed, that Amazon API returns 403 response when trying to request only headers:

curl "https:/..." --head            
HTTP/1.1 403 Forbidden
x-amz-request-id: 9A0D5596C066E400
x-amz-id-2: Cb1y8kEjyPKd3JzpaxV8cGAsXvA9tzlLaCy4l/HP1qBfaRMIR9Q/da0tnpHUfItbyH8P7WmokkI=
Content-Type: application/xml
Date: Tue, 23 Feb 2021 07:01:38 GMT
Server: AmazonS3

While, ordinary request works fine

 curl "https://..." --output file.docx
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 38010  100 38010    0     0   123k      0 --:--:-- --:--:-- --:--:--  123k

What is the reason for this?

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.