diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/DocumentLayoutExample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/DocumentLayoutExample.java index 95777b436..e1f411849 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/examples/DocumentLayoutExample.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/DocumentLayoutExample.java @@ -34,6 +34,9 @@ public class DocumentLayoutExample extends SDKSample { public static final String APPLY_LAYOUT_DOCUMENT_NAME = "Apply Layout Document"; public static final String APPLY_LAYOUT_DOCUMENT_ID = "docId"; public static final String APPLY_LAYOUT_DOCUMENT_DESCRIPTION = "Document with applied layout description."; + public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_NAME = "Apply Layout Document by Name"; + public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_ID = "docId2"; + public static final String APPLY_LAYOUT_BY_NAME_DOCUMENT_DESCRIPTION = "Document with applied layout by name description."; public static void main(String... args) { new DocumentLayoutExample().run(); @@ -89,12 +92,19 @@ public void execute() { .withId(APPLY_LAYOUT_DOCUMENT_ID) .withDescription(APPLY_LAYOUT_DOCUMENT_DESCRIPTION) .fromStream(documentInputStream2, DocumentType.PDF)) + .withDocument(newDocumentWithName(APPLY_LAYOUT_BY_NAME_DOCUMENT_NAME) + .withId(APPLY_LAYOUT_BY_NAME_DOCUMENT_ID) + .withDescription(APPLY_LAYOUT_BY_NAME_DOCUMENT_DESCRIPTION) + .fromStream(documentInputStream3, DocumentType.PDF)) .build(); packageId = eslClient.createPackage(packageFromLayout); // Apply the layout to document in package eslClient.getLayoutService().applyLayout(packageId, APPLY_LAYOUT_DOCUMENT_ID, layoutId); + + // Apply the layout by name to document in package + eslClient.getLayoutService().applyLayout(packageId, APPLY_LAYOUT_BY_NAME_DOCUMENT_ID, LAYOUT_PACKAGE_NAME); packageWithLayout = eslClient.getPackage(packageId); } diff --git a/sdk/src/main/java/com/silanis/esl/sdk/examples/SDKSample.java b/sdk/src/main/java/com/silanis/esl/sdk/examples/SDKSample.java index b1b4f77c5..3a06a88c1 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/examples/SDKSample.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/examples/SDKSample.java @@ -16,7 +16,7 @@ abstract public class SDKSample { protected PackageId packageId; protected String packageName; protected DocumentPackage retrievedPackage; - protected InputStream documentInputStream1, documentInputStream2; + protected InputStream documentInputStream1, documentInputStream2, documentInputStream3; protected Properties props = Props.get(); @@ -68,6 +68,7 @@ private void setProperties() { documentInputStream1 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" ); documentInputStream2 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" ); + documentInputStream3 = this.getClass().getClassLoader().getResourceAsStream( "document.pdf" ); } protected EslClient getEslClient() { diff --git a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java index 3dffc2a83..fffa748af 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/internal/UrlTemplate.java @@ -143,6 +143,7 @@ public class UrlTemplate { public static final String LAYOUT_PATH = "/layouts"; public static final String LAYOUT_LIST_PATH = "/layouts?to={to}&from={from}&dir={dir}"; public static final String APPLY_LAYOUT_PATH = "/packages/{packageId}/documents/{documentId}/layout?layoutId={layoutId}"; + public static final String APPLY_LAYOUT_PATH_BY_NAME = "/packages/{packageId}/documents/{documentId}/layout?layoutName={layoutName}"; // QR Code Service public static final String QRCODE_PATH = "/packages/{packageId}/documents/{documentId}/fields"; diff --git a/sdk/src/main/java/com/silanis/esl/sdk/service/LayoutService.java b/sdk/src/main/java/com/silanis/esl/sdk/service/LayoutService.java index 71df1e40f..c2833c8d9 100644 --- a/sdk/src/main/java/com/silanis/esl/sdk/service/LayoutService.java +++ b/sdk/src/main/java/com/silanis/esl/sdk/service/LayoutService.java @@ -144,5 +144,29 @@ public void applyLayout(PackageId packageId, String documentId, String layoutId) throw new EslException("Could not apply layout." + " Exception: " + e.getMessage()); } } + + /** + * Apply a document layout to a document in a DocumentPackage. Adds fields to signer's signature or if the signer + * does not exist, will create placeholders. + * + * @param packageId The package id of the DocumentPackage to apply layout. + * @param documentId The document id of the document to apply layout. + * @param layoutName The layout name of the layout to apply. + */ + public void applyLayoutByName(PackageId packageId, String documentId, String layoutName) { + String path = template.urlFor(UrlTemplate.APPLY_LAYOUT_PATH_BY_NAME) + .replace("{packageId}", packageId.getId()) + .replace("{documentId}", documentId) + .replace("{layoutName}", layoutName) + .build(); + + try { + client.post(path, ""); + } catch (RequestException e) { + throw new EslServerException("Could not apply layout.", e); + } catch (Exception e) { + throw new EslException("Could not apply layout." + " Exception: " + e.getMessage()); + } + } }