您正在檢視適用於以下版本的說明內容::

You can enable Watch Folder functionality in AEM by creating a workflow and a launcher for the workflow.

See Workflow Documentation for details around creating workflows. 

See Launcher Documentation for details around creating launchers. 

The attached sample workflow and launcher merges a template/data using the centralMerge method of OutputCentralService. In addition, it sends the generated PCL document to a printer using the sendToPrinter API.

Using sample workflow and launcher

  1. Ensure that the latest AEM Forms 6.0 add-on package adobe-aemfd-{OS}-pkg is installed.

  2. Install attached adobe-aemfd-cmb-sample-pkg.

    下載

  3. Navigate to http://<cqhost>:<port>/workflow and search for AEMFD CMB Sample Workflow - Merge and Print in the Models tab.

  4. Select AEMFD CMB Sample Workflow - Merge and Print, and click Edit. The workflow is opened in the Workflow editor.

  5. Double-click the AEMFD CMB Sample Workflow step, and open the Process tab.

  6. In the Arguments field, enter the path to template (.mdf) and details of the printer. Arguments is a list of comma-separated values. Values are interpreted as a list (path to the MDF file, PrintServer, PrinterName, PrinterProtocol).

  7. Click Ok, and then click Save.

The launcher is configured to pick files you drop at the location /content/fd/cmb/samples/MergeAndPrint/watchfolder.

Drop a data file (.dat) in a watch folder to trigger the workflow to render PCL and print it.

Creating a Watch folder

In the sample use case, you create a Watch folder and copy a data (.dat) file to the folder. This data file is merged with a template (.mdf) and the generated PCL (.pcl) file is the sent to printer using the print API of SendToPrinter Service for printing.

註解:

Refer to the section if you want to create an AEM Workflow and Launcher for use with CMB service from scratch. Skip the section if you only want to use the adobe-aemfd-cmb-sample-pkg package because it already implements the details covered here. 

Creating the Workflow step

In this sample, you use the ECMAScript to define a Workflow Process step that performs following operations:

  • Read .mdf and .dat files from payload and merge them to generate a PCL document using the centralMerge operation of the CBM service.
  • Send the PCL document to a printer using print API of SendToPrinter Service

Log in to the CRX repository, create the file /etc/workflow/scripts/cmb/cmb-mergeandprint-sample.ecma, and paste the following code:

/**
 *  Sample Workflow Step to demo OutputCentralService and sendToPrinter functionality of SendToPrinterService
 *
 *  Process Arguments
 *  1. inTemplate ( Absolute template file path e.g. "/content/cmb/excomma.mdf")
 *  2. printServer ( print server name e.g. \\mytestprinter)
 *  3. printerName ( name of the printer)
 *  4. printerProtocol (protocol to use to print cifs,directip etc.)
 *
 */
// Begin
var logger = Packages.org.slf4j.LoggerFactory.getLogger("cmb-mergeandprint-sample.ecma");
/*
 * Reference to OutputCentralService, used to invoke centralMerge operation
 */
var centralMigrationBridgeService = sling.getService(Packages.com.adobe.fd.cmb.api.OutputCentralService);
/**
 * Reference to SendToPrinterService, used to invoke sendToPrinter API
 */
var stpService = sling.getService(Packages.com.adobe.fd.stp.api.SendToPrinterService);
/*
 * workflow payload and path to it
 */
var payload = graniteWorkItem.getWorkflowData().getPayload();
var payload_path = payload.toString();
/*
 *  Template file Document
 */
var inTemplateDocument = readDocument(args[0]);
/*
 * data file argument
 */
var inDataDocument = readDocument(payload_path);
/*
 * printServer argument
 */
var printServer = args[1];
/*
 * printerName argument
 */
var printerName = args[2];
/*
 * printerProtocol
 */
var printerProtocol = args[3];
/*
 * authentication info
 */
var userName = args[4];
var password = args[5];
var domain = args[6];
 
/*
 * Generate PCL document by merging input data with template file using central migration bridge service
 */
var centralResult = centralMigrationBridgeService.centralMerge(inTemplateDocument,inDataDocument,null, null, null, null);
var pclDocument = centralResult.getResultDoc();
logger.info("Generated PCL Document : "+pclDocument);
/*
 * send pcl document to printer for printing using SendToPrinter services's print API
 */
// create printer spec for the printer
var printerSpec = new Packages.com.adobe.fd.stp.api.PrinterSpec();
printerSpec.setPrintServer(printServer);
printerSpec.setPrinterName(printerName);
setPrinterProtocol(printerSpec, printerProtocol);
if(userName) {
 printerSpec.setUsername(userName);
}
if(password){
  printerSpec.setPassword(password);
}
if(domain){
  printerSpec.setDomain(domain);
}
// call service now
 stpService.print(pclDocument,printerSpec);
logger.info("SuccessFully Printed pclDocument to "+printServer+","+printerName);
// END of Main Script
/** #########################################
 *   Utility methods
 *  ################################################
 */
 
/**
 *  reads the nt:file node's jcr:content property and creates a document object from it.
 */
function readDocument(path_str){
    var jcrsession = graniteWorkflowSession.adaptTo(Packages.javax.jcr.Session);
    var node = jcrsession.getRootNode().getNode(path_str.substring(1));
    var is = node.getProperty("jcr:content/jcr:data").getStream();
    return new Packages.com.adobe.aemfd.docmanager.Document(is);
}
/**
 * Converts printer protocol string to com.adobe.fd.stp.api.PrinterProtocol enum
 *
 */
function setPrinterProtocol(printerSpec, protocol_str){
    if(protocol_str == null || typeof(protocol_str) == "undefined" || protocol_str.length() == 0){
        throw new Error("getPrinterProtocol#protocol_str is null");
    }
    protocol_str = protocol_str.trim();
    if("CUPS".equals(protocol_str)){
       printerSpec.setPrinterProtocol(Packages.com.adobe.fd.stp.api.PrinterProtocol.CUPS);
    } else if("DirectIP".equals(protocol_str)){
       printerSpec.setPrinterProtocol(Packages.com.adobe.fd.stp.api.PrinterProtocol.DirectIP);
    } else if("LPD".equals(protocol_str)){
       printerSpec.setPrinterProtocol(Packages.com.adobe.fd.stp.api.PrinterProtocol.LPD);
    } else if("SharedPrinter".equals(protocol_str)){
       printerSpec.setPrinterProtocol(Packages.com.adobe.fd.stp.api.PrinterProtocol.SharedPrinter);
    } else if("CIFS".equals(protocol_str)){
       printerSpec.setPrinterProtocol(Packages.com.adobe.fd.stp.api.PrinterProtocol.CIFS);
    } else {
       throw new Error("Unknown protocol "+protocol_str);
    }
}

Creating a workflow

To be able to use the Workflow step, include it in a workflow. Perform the following steps to create a workflow that uses the Workflow step:

  1. Navigate to http://<server>:<port>/workflow and log in with your credentials.

  2. In the Models tab, click New, provide a title, and click Ok to create a blank workflow.

  3. Now search the workflow you created and double-click it. The Workflow editor is displayed.

  4. In the Workflow editor, drag a Process step from the Workflow section of Sidekick.

  5. Double-click the new workflow step, and select the Process tab in the dialog.

  6. In the Process list, select the file /etc/workflow/scripts/cmb/cmb-mergeandprint-sample.ecma.

  7. Select Handler Advance to ensure that the workflow moves to the next step automatically.

  8. In the Arguments section, add comma-separated values as path to template (.mdf), PrintServer, PrinterName, and PrinterProtocol.

  9. Click Ok, and then click Save.

Creating a launcher

When the workflow is ready, perform the following steps to create a launcher to call the workflow.

  1. Navigate to http://<server>:<port>/workflow and log in with your credentials.

  2. In the Launcher tab, click Add.

  3. In the dialog, select Event Type as Created and Node Type as nt:file. Also, set the path to the folder that you want to designate as a watch folder.

  4. From the Workflow list, select the workflow you created earlier.

  5. Select a run mode. and click OK. Your watch folder is ready for use.

    Launcher configuration
    Launcher configuration

    註解:

    If the runModes property is not specified for the Watched Folder, then the Watched Folder always activates regardless of the run-modes on the hosting server.

此産品由 Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License 授權  Creative Commons 條款未涵蓋 Twitter™ 與 Facebook 文章。

法律說明   |   線上隱私權政策