Code Monkey home page Code Monkey logo

Comments (9)

ikr0m avatar ikr0m commented on May 11, 2024

I'm using java 8, playframework, scala, sbt.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 11, 2024

Out of the box it is not possible, but the missing parts could be added with little effort. I find the idea quite interesting so I will check how to do this (within a week) and come back to you with my results.

The missing parts are that fodt is not supported by default (but can be added easily, I'll open an issue to support it by default) and the other part would be to create a Filter that would merge a document to the original document being converted. Such a filter could then be added to the filter chain for each document to merge.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 11, 2024

Could you please try the latest version of the master branch? You will have to use the new DocumentInserterFilter in order to merge documents. Using the same example you provided:

final DocumentInserterFilter inserterFilter = new DocumentInserterFilter(new File("extra.fodt"));

// Merge a.fodt with extra.fodt to produce result.pdf
LocalConverter
  .builder()
  .filterChain(inserterFilter)
  .build()
  .convert(new File("a.fodt"))
  .to(new File("result.pdf"))
  .execute();

// Merge b.fodt with extra.fodt to produce result2.pdf
LocalConverter
  .builder()
  .filterChain(inserterFilter)
  .build()
  .convert(new File("b.fodt"))
  .to(new File("result2.pdf"))
  .execute();

Note that you can merge multiple documents. The following example would merge a.fodt, b.fodt, c.fodt and extra.fodt to produce result.pdf:

final DocumentInserterFilter bFilter = new DocumentInserterFilter(new File("b.fodt"));
final DocumentInserterFilter cFilter = new DocumentInserterFilter(new File("c.fodt"));
final DocumentInserterFilter extraFilter = new DocumentInserterFilter(new File("extra.fodt"));

// Merge a.fodt with extra.fodt to produce result.pdf
LocalConverter
  .builder()
  .filterChain(bFilter , cFilter, extraFilter)
  .build()
  .convert(new File("a.fodt"))
  .to(new File("result.pdf"))
  .execute();

from jodconverter.

ikr0m avatar ikr0m commented on May 11, 2024

Thank you for positive response and effort! I'll try to use it soon.

from jodconverter.

ikr0m avatar ikr0m commented on May 11, 2024

Tried to concatenate 2 fodt files and generate pdf file:

val fodt1 = Paths.get("/path/to/file1.fodt").toFile
val fodt2 = Paths.get("/path/to/file2.fodt").toFile
val pdfMerged = Paths.get("/path/to/merged_3.pdf").toFile

val inserterFilter = new DocumentInserterFilter(fodt1)

LocalConverter
    .builder()
    .filterChain(inserterFilter)
    .build()
    .convert(fodt2)
    .to(pdfMerged)
    .execute()

But merged_3.pdf file contains only file1.fodt file content. It's ignoring fodt2.

from jodconverter.

sbraconnier avatar sbraconnier commented on May 11, 2024

Which version of LibreOffice is it ? Is it possible for you to provide me with files (removing all sensitive data) I could use to reproduce your problem. On my end, everything works just fine.

Can you try the 4.1.1-SNAPSHOT version available in the OSS snapshots repository:
https://oss.sonatype.org/content/repositories/snapshots/

from jodconverter.

ikr0m avatar ikr0m commented on May 11, 2024

libreoffice version is LibreOffice 5.1.6.2 10m0(Build:2)
This is the code:

  val officeManager = LocalOfficeManager.builder().install().build()
  officeManager.start()
  val fodt1 = Paths.get("/home/user/tmp/files/test1.fodt").toFile
  val fodt2 = Paths.get("/home/user/tmp/files/test2.fodt").toFile
  val pdfMerged = Paths.get("/home/user/tmp/files/test_result.pdf").toFile
  val inserterFilter = new DocumentInserterFilter(fodt1)
  LocalConverter
      .builder()
      .filterChain(inserterFilter)
      .build()
      .convert(fodt2)
      .to(pdfMerged)
      .execute()

Attaching 3 files. Input (test1.fodt, test2.fodt) and output (test_result.pdf). Archived fodt files because github didn't allow to attach them.
test_result.pdf
test_fodt_files.tar.gz

from jodconverter.

sbraconnier avatar sbraconnier commented on May 11, 2024

That one is not easy... It seems to be related to "fodt" format. If you convert the fodt to odt first, it works:

  val officeManager = LocalOfficeManager.builder().install().build()
  officeManager.start()
  val fodt1 = Paths.get("/home/user/tmp/files/test1.fodt").toFile
  val odt1 = Paths.get("/home/user/tmp/files/test1.odt").toFile
  val fodt2 = Paths.get("/home/user/tmp/files/test2.fodt").toFile
  val odt2 = Paths.get("/home/user/tmp/files/test2.odt").toFile
  val pdfMerged = Paths.get("/home/user/tmp/files/test_result.pdf").toFile

  LocalConverter.make().convert(fodt1).to(odt1).execute()
  LocalConverter.make().convert(fodt2).to(odt2).execute()

  val inserterFilter = new DocumentInserterFilter(odt1)

  LocalConverter
      .builder()
      .filterChain(inserterFilter)
      .build()
      .convert(odt2)
      .to(pdfMerged)
      .execute()

I'll try to find out why, but I'm not that confident that I'll find a better option...

from jodconverter.

ikr0m avatar ikr0m commented on May 11, 2024

Thanks! That is useful too.

from jodconverter.

Related Issues (20)

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.