U bekijkt help-inhoud voor de versie::
- 6.3
- 6.2
- Eerdere versies
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.
-
Downloaden
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.
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.
Opmerking:
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.
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); } }
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: