aem 渲染
业务用例 (The business use case)
An organization wants to provide a seamless onboarding experience to their prospective users. The organization wants to do this by allowing their users to switch from an online to an offline PDF form mid-way or even download an offline form to start the process where they can continue to enter their details and finally submit the information. This will provide a seamless onboarding experience to the user thus leading to more satisfied users in the long run.
一个组织希望为其潜在用户提供无缝的入职体验。 该组织希望通过允许其用户在中途从在线PDF表单切换到离线PDF表单,甚至下载离线表单来启动流程,从而继续输入自己的详细信息并最终提交信息来做到这一点。 从长远来看,这将为用户提供无缝的入职体验,从而使用户更加满意。
![Image for post](https://miro.medium.com/max/9999/1*yxixCzBvpuCLVBtYC9_GwA.png)
Pre-requisites
先决条件
- AEM 6.4+ AEM 6.4以上
- Forms Add-on 表单附件
- AEM Maven project should have the following dependencies (artifactId) AEM Maven项目应具有以下依赖关系(artifactId)
adobe-lc-forms-bedrock-connector
adobe-aemds-core-docmanager
adobe-aemfd-docassurance
adobe-aemfd-readerextensions
adobe-aemfd-signatures
com.adobe.aemfd
Solution
解
The solution is to use AEM forms technology and leveraging the reader extension mechanism where a PDF form can be enabled for editing to the end user. The process of programmatically enabling reader extension in the application is a technical one and comprises of the following steps
解决方案是使用AEM表单技术并利用阅读器扩展机制,在该机制中可以启用PDF表单以供最终用户编辑。 在应用程序中以编程方式启用阅读器扩展的过程是技术性的过程,包括以下步骤
- Open the sling.properties that is there in the folder crx-quickstart/conf folder of your AEM extension and add the below lines 打开AEM扩展文件夹crx-quickstart / conf文件夹中的sling.properties,并添加以下几行
sling.bootdelegation.class.com.rsa.jsafe.provider.JsafeJCE=com.rsa.*
sling.bootdelegation.class.org.bouncycastle.jce.provider.BouncyCastleProvider=org.bouncycastle.
2. Configure the Apache Sling Service User Mapper Service for user fd-service and add a mapping in the format of ‘bundleId [ “:” subServiceName ] “=” userName’
2.为用户fd-service配置Apache Sling服务用户映射程序服务,并以'bundleId [“:” subServiceName]“ =” userName“的格式添加映射
3. Add the same mapping in Apache Sling Service User Mapper Service Amendment
3.在Apache Sling Service用户映射器服务修订中添加相同的映射
Steps 2 and 3 are required in order to get the repository connection and is the preferred way instead of using resolverFactory.loginAdministrative
步骤2和3是获得存储库连接所必需的,是代替使用resolverFactory.loginAdministrative的首选方法
4. The next step is to create a keystore for user fd-service and adding the provided certificate for the reader extension
4.下一步是为用户fd-service创建密钥库,并为阅读器扩展添加提供的证书
a) Go to AEM Logo -> Tools -> Security -> Users -> fd-service
a)转到AEM徽标->工具->安全->用户-> fd-service
![Image for post](https://miro.medium.com/max/9999/1*M6WHRdyv2TENYqsnvN5kFQ.png)
![Image for post](https://miro.medium.com/max/9999/1*l4GoLaPAyEyCf0LbA8W5rQ.png)
b) Clicking on Keystore will bring up the screen
b)单击密钥库将弹出屏幕
![Image for post](https://miro.medium.com/max/9999/1*mbNfNBWo1Fk9hwahCbGVGw.jpeg)
c) Clicking on Create Keystore will bring up the screen
c)单击创建密钥库将弹出屏幕
![Image for post](https://miro.medium.com/max/9999/1*wLwSuvKvs-XcJVEQG8GkkQ.jpeg)
d) Add a New Password and click Save after adding in both fields. This will bring up
d)添加新密码,并在两个字段中添加后单击保存。 这会带来
![Image for post](https://miro.medium.com/max/9999/1*SyBuKD7GVtRmyHr1vmp5hw.jpeg)
e) Enter data in the relevant section in the above screen. The following needs to be entered for the fields
e)在以上屏幕的相关部分中输入数据。 需要在字段中输入以下内容
"realias" for New AliasSelect the provided PFX file that you would be having for the field Keystore FileEnter the password for the PFX file in the fields Keystore File Password and Private Key Password The Private Key Alias can be extracting by executing the command "keytool list -v -keystore <path to PFX file> -storetype pkcs12"
新别名的“ realias”选择提供给密钥库文件的PFX文件。在密钥库文件密码和私钥密码字段中输入PFX文件的密码。可以通过执行命令“ keytool list”来提取私钥别名。 -v -keystore <PFX文件的路径> -storetype pkcs12“
f) Click on Save and Close to exit the editing of fd-service.
f)单击保存并关闭以退出fd服务的编辑。
5) The AEM form is created based on a XSD schema which allows us to Download a Document of Record as a XDP file. This can be done by clicking on the Download Document of Record link as shown in the below screenshot
5)AEM表单是基于XSD架构创建的,该架构允许我们将记录文档下载为XDP文件。 这可以通过单击“下载记录的文档”链接来完成,如下面的屏幕快照所示。
![Image for post](https://miro.medium.com/max/9999/1*VQZ-k2NgTQvp1jsT2wJRzA.png)
6) The XDP file can be saved as Adobe Dynamic XML (PDF) using Livecycle Designer which can be stored in AEM as a template.
6)可以使用Livecycle Designer将XDP文件另存为Adobe Dynamic XML(PDF),可以将其作为模板存储在AEM中。
a) This template can be provided on need basis and the data in the XML from the online form can be merged programmatically and provided for download as an offline form to the end user. This step is only for scenarios where a user is either filling up an online form and wants to save a draft on their system or there is a requirement to merge with some data from the system. A code snippet is provided below
a)可以根据需要提供此模板,并且可以以编程方式合并来自在线表单的XML数据,并可以将其作为脱机表单下载给最终用户。 此步骤仅适用于以下情况:用户要么填写在线表单并想在其系统上保存草稿,要么需要与系统中的某些数据合并。 下面提供了一个代码段
org.w3c.dom.Node result = (org.w3c.dom.Node) xPath.evaluate("afData/afBoundData/details", doc, XPathConstants.NODE);Document xmlDocument = newDocument pdfDocument = newDocument generatedDocument = this.formsService.importData(pdfDocument, xmlDocument);
b) The next step is to programmatically apply the reader extension to the generated document before being sent for download as an offline PDF. A code snippet is provided below. Note that the credential alias is same as the value that was provided at the time of creating the KeyStore.
b)下一步是将阅读器扩展程序以编程方式应用于生成的文档,然后再发送为脱机PDF下载。 下面提供了一个代码段。 请注意,凭证别名与创建KeyStore时提供的值相同。
public Document enableReaderExtension(Document document, ResourceResolver resolver) throws Exception {UsageRights usageRights = new
usageRights.setEnabledFormFillIn(true);
usageRights.setEnabledDigitalSignatures(true);
usageRights.setEnabledEmbeddedFiles(true);
usageRights.setEnabledFormDataImportExport(true);ReaderExtensionOptions readerOpts = ReaderExtensionOptions.getInstance();readerOpts.setReOptions(new
readerOpts.setCredentialAlias("realias");
readerOpts.setResourceResolver(resolver);ReaderExtensionsOptionSpec reOptionsSpec = new
readerOpts.setReOptions(reOptionsSpec);return}
7) The Document that is returned from the above method is then finally made available for download to the user. A code snippet is provided below
7)从上述方法返回的文档最终可以下载给用户。 下面提供了一个代码段
Document generatedDocument = this.docService.enableReaderExtension(generatedDocument, resolver);
outputInStream = generatedDocument.getInputStream();response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=accountapplication.pdf");
out = response.getOutputStream();
byte[] buffer = new byte[4096];
int length;
while ((length = outputInStream.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
out.flush();
摘要 (Summary)
Finally, using the above steps, a user will have an offline PDF form on their device/desktop, on which they can fill up the information. The information will be sent to the server once the user clicks on the Submit button on the form.
最后,使用上述步骤,用户将在设备/桌面上拥有离线PDF表单,他们可以在其中填写信息。 用户单击表单上的“提交”按钮后,该信息将发送到服务器。
Referring all of the above, it should be clear on how to programmatically apply the reader extension on an offline PDF form and allow the users to submit information once they come online.
参照以上所有内容,应该清楚地了解如何以编程方式将阅读器扩展名应用于脱机PDF表单,并允许用户在联机后提交信息。
It should be easy to implement the same in any AEM Forms implementation that meets the pre-requisites.
在满足先决条件的任何AEM Forms实现中,应易于实现相同的目的。
翻译自: https://medium.com/adobetech/enabling-reader-extension-to-pdf-using-aem-forms-apis-1788419869c
aem 渲染