0

I used a service to get one docx in binary content and I have one docx file which I'am able to convert to binary content now If I try to write both to byte array and when I open either I found only one document or I was not able to open the document .The code can be seen below

    Byte [] a = (byte[])obj1;
Byte [] b = (byte[])obj2;
    Outputstream op= new outputstream();
Try {
Op.write(a);
Op write(b);
Byte[] combined = op.toByteArray();

Final byte array - combined either contain only one docx file or It became s unreadable. Need a solution without any extra jars.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
Gilli
  • 1
  • It's hardly doable without "extra" code since DOCX is a bit more complex format than just an array of bytes. If it is strictly required to have no extra jars, you can manually add source code of some tool (that is designed for DOCX merging) into your project, respecting the license of course. Tools are observed here https://stackoverflow.com/a/2494642/2224047 – Nikolai Shevchenko Jan 26 '22 at 07:55
  • Using java runtime alone is difficult for merging DOCX. Your best bet is to use a java library with classes for document format processing. The LEADTOOLS toolkit, for example, has the [LEADDocument](https://www.leadtools.com/help/sdk/v22/dh/dox/leaddocument.html) class which can encapsulate loaded DOCX files and can be used to merge them into a single file. This functionality is also available through a [Cloud Service](https://www.leadtools.com/help/sdk/v22/tutorials/cloud-services-java-merge-documents.html). (Disclaimer: I am an employee of the vendor). – Hussam Barouqa Feb 03 '22 at 22:25

0 Answers0