Request: Question
Version: Latest (currently v8.3.3.22)
Installation Type: Docker
OS: Ubuntu - WSL 2 (Windows 11)
Language: Java
Hello everyone,
I’m currently integrating OnlyOffice and Document Builder into a web application to evaluate whether they meet my feature requirements.
At the moment, I’m working with Java and Maven, and I need help setting up the Document Builder SDK for Java using Maven.
As of now, the Document Builder documentation does not provide instructions for installing the SDK via Maven.
Here’s what I’ve tried so far — which builds successfully in Maven — by adding the following to my pom.xml
:
<dependency>
<groupId>docbuilder</groupId>
<artifactId>com.onlyoffice.docbuilder</artifactId>
<version>8.3.3.22</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/onlyoffice/docbuilder.jar</systemPath>
</dependency>
However, when I attempt to use any class from the JAR, I get the following error:
jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: docbuilder/CDocBuilder
...
Caused by: java.lang.ClassNotFoundException: docbuilder.CDocBuilder
Any guidance or suggestions on how to resolve this would be greatly appreciated.
Best regards,
Cyprien
Additionally, I’d like to know how I can proceed with the following tasks using Document Builder:
- Open a template file (DOCX or HTML)
- Replace a specific merge field with the content of another DOCX or HTML file
- Start a mail merge run
- Replace all remaining fields
- Retrieve the final document as a buffer (ideally without writing a file locally, not even to a temporary folder)
Here’s what I’m considering so far:
- Use the
ToJson
method to extract the content of the secondary DOCX/HTML file
- Store that JSON content in a variable
- Open the main template file
- Replace the target merge field either inside or outside of a run
- Attempt to call a
downloadAs
or similar method—if available—to retrieve the file as a stream or buffer from the response url.
Does this approach make sense? And is there a better or more recommended way to handle this flow?
Thanks in advance!
Hello @Cyprien
Please elaborate on this statement. What is your ultimate goal? Are you trying to integrate ONLYOFFICE Docs (Document Server) with your app to enhance it with capability of running editor inside of your app or you wish to utilize Document Builder to generate documents without running the editor in your app?
It is important to keep in mind and Document Server and stand-alone Document Builder are different apps, so the integration process will differ, depending in the desired goal.
Hi Constantine,
Thanks for the follow-up.
To clarify: I’ve already integrated the OnlyOffice Docs editor into the front end of my application. What I’m aiming to do now is use Document Builder on the backend to perform mail merge operations, inject variables, and then retrieve the final document as a buffer—without writing it to disk at any point (not even temporarily).
My use case:
-
I have a DOCX template that includes merge fields (like {{date}}
, {{section_content}}
, etc.).
-
I also have another DOCX file whose content should replace a specific merge field (e.g., {{section_content}}
).
-
In addition to that, I need to fill other fields like the date and recipient name.
-
Once the merge is complete, I need the output as a byte buffer so I can store it directly in the database or serve it through an API—no local file writing involved.
What I’ve considered:
-
Extract the content of the secondary DOCX using ToJson
.
-
Store that JSON in memory.
-
Load the main template.
-
Replace the target merge field with the JSON content, and fill in the rest of the fields.
-
Retrieve the final merged document as a buffer or stream.
Does this seem like the right approach? And if there’s a better way to achieve this kind of in-memory transformation using Document Builder, I’d be grateful for your guidance.
Thanks again!
Best regards,
Cyprien
Firstly, Document Builder is also packaged as Web API service of Document Server. Please refer to the following documentation:
Basically, you can utilize it instead of stand-alone version.
Secondly, please elaborate on this goal:
Do I understand correctly that you do not want to actually modify the contents of any files? Generally speaking, you would like to get some necessary information from file 1, apply it to the file 2 and then save contents of the file 2 as, for instance, a string, but do not save those applied changes, is that right?
I have to note right there that Document Builder, either web one or stand alone, can only save documents in documents formats (DOCX, PDF, ODT, etc.).