public void appendToDoc( InputStream input, OutputStream output, Map keyMap, Map signMap, String html, String frmt, byte[] empSign, byte[] rimDirSign, byte[] sjrlogo, byte[] srvcCntr, SearchAndReplaceCallBack callback) throws Exception { Document doc = null; if (input == null) { doc = convertHtml(html, "potriat", null, "normal", "doc", null, srvcCntr, null, true); } else if (srvcCntr != null) { doc = AsposeLic.createDocument(new ByteArrayInputStream(srvcCntr)); Document srcDoc = AsposeLic.createDocument(input); srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS); doc.appendDocument(srcDoc, ImportFormatMode.USE_DESTINATION_STYLES); } else { doc = AsposeLic.createDocument(input); } Map<String, Object> map = AsposeUtility.getKeyTemplates(); AsposeUtility.InsertDocumentAtReplaceHandler handler = new AsposeUtility.InsertDocumentAtReplaceHandler(); for (Map.Entry<String, Object> entry : map.entrySet()) { if (keyMap.containsKey(entry.getKey())) { String key = entry.getKey(); Object val = keyMap.get(key); if (val instanceof InputStream) { AsposeUtility.replaceDoc( doc, "\\[\\[\\[" + key + "\\]\\]\\]", (InputStream) val, (key.contains("DRAFT") ? true : false), handler); } else if (val instanceof String) { AsposeUtility.replaceHtmlToDoc( (String) val, doc, "\\[\\[\\[" + key + "\\]\\]\\]", (key.contains("DRAFT") ? true : false), handler); } } } replaceSignatures(doc, empSign, rimDirSign, sjrlogo, callback); AsposeUtility.replaceHtmlVariables(doc, keyMap); AsposeUtility.replaceVariables(doc, signMap); AsposeUtility.cleanupDoc(doc); if (frmt != null && frmt.equals("doc")) { doc.save(output, SaveFormat.DOC); } else { doc.save(output, SaveFormat.PDF); } }