Here are the key reasons to use the new updated API provided by GroupDocs.Merger for Java since version 19.12:
Merger class introduced as a single entry point to manage the document processing of any supported file format (instead of DocumentHander class from previous versions).
Product architecture was redesigned from scratch in order to decreased memory usage (from 10% to 400% approx. depending on document type).
Document processing API simplified and improved so it’s easy to instantiate proper options class and control over document structure manipulation processes.
How To Migrate?
Here is a brief comparison of how to join documents using old and new API.
Old coding style
// Preparing.
Stringpassword="SomePasswordString";InputStreamdocumentExample1=newFileInputStream("c:\\sample1.docx");InputStreamdocumentExample2=newFileInputStream("c:\\sample2.docx");List<JoinItem>documentStreams=newArrayList<JoinItem>();JoinItemitem1=newJoinItem(documentExample1,FileFormat.Pdf,password);documentStreams.add(item1);JoinItemitem2=newJoinItem(documentExample2,FileFormat.Pdf,password);documentStreams.add(item2);// Main method.
DocumentResultresult=newDocumentHandler().join(documentStreams);OutputStreamdocumentStream=result.getStream();ByteArrayOutputStreambyteArrayStream=(ByteArrayOutputStream)documentStream;byte[]bytes=byteArrayStream.toByteArray();FileOutputStreamfos=newFileOutputStream(CommonUtilities.outputPath+fileName);fos.write(bytes,0,bytes.length);fos.close();