Reader extension enablement using AEM

Avatar

Avatar

amolchavan21

Avatar

amolchavan21

amolchavan21

26-09-2018

Can AEM designer be used to enable reader extension on a PDF?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Mayank_Gandhi

Employee

Avatar

Mayank_Gandhi

Employee

Mayank_Gandhi
Employee

26-09-2018

No, you will need an AEM forms Server or Acrobat to reader extend a pdf.

If you have AEM forms JEE server you can use workbench or ReaderExtension UI while with Acrobat you have to just save the form again using File -> Save as Other -> Reader extended PDF

1580019_pastedImage_0.png

Answers (5)

Answers (5)

Avatar

Avatar

workflowuser

Employee

Avatar

workflowuser

Employee

workflowuser
Employee

15-08-2019

I will put out a sample on this soon

Avatar

Avatar

Mayank_Gandhi

Employee

Avatar

Mayank_Gandhi

Employee

Mayank_Gandhi
Employee

15-08-2019

Yes, Aem forms OSGi provides reader extension capabilities as well.

Avatar

Avatar

workflowuser

Employee

Avatar

workflowuser

Employee

workflowuser
Employee

15-08-2019

is this what you wanted?

ApplyReaderExtensions

I will create an article on this soon

the following is the code needed to get this working

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

import com.adobe.aemfd.docmanager.Document;

import com.adobe.fd.docassurance.client.api.DocAssuranceService;

import com.adobe.fd.docassurance.client.api.ReaderExtensionOptions;

import com.adobe.fd.readerextensions.client.ReaderExtensionsOptionSpec;

import com.adobe.fd.readerextensions.client.UsageRights;

import com.adobe.fd.signatures.pdf.inputs.UnlockOptions;

import com.aemforms.ares.core.ReaderExtendPDF;

import com.mergeandfuse.getserviceuserresolver.GetResolver;

@Component(service=ApplyUsageRights.class,immediate = true)

public class ApplyUsageRights implements ReaderExtendPDF {

@Reference

DocAssuranceService docAssuranceService;

@Reference

GetResolver getResolver;

@Override

public Document applyUsageRights(Document pdfDocument,UsageRights usageRights) {

   ReaderExtensionsOptionSpec reOptionsSpec = new ReaderExtensionsOptionSpec(usageRights, "Sample ARES");

   UnlockOptions unlockOptions = null;

   ReaderExtensionOptions reOptions = ReaderExtensionOptions.getInstance();

   reOptions.setCredentialAlias("ares");

 

   reOptions.setResourceResolver(getResolver.getFormsServiceResolver());

 

   reOptions.setReOptions(reOptionsSpec);

   System.out.println("Applying Usage");

try {

return docAssuranceService.secureDocument(pdfDocument, null, null, reOptions,

     unlockOptions);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

}

public class GetReaderExtendedPDF extends SlingAllMethodsServlet {

@Reference

GetResolver getResolver;

@Reference

ApplyUsageRights applyRights;

public org.w3c.dom.Document w3cDocumentFromStrng(String xmlString) {

try {

DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();

InputSource is = new InputSource();

is.setCharacterStream(new StringReader(xmlString));

return db.parse(is);

} catch (ParserConfigurationException e) {

e.printStackTrace();

} catch (SAXException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return null;

}

@Override

protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response)

{

doPost(request,response);

}

@Override

protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) {

UsageRights usageRights = new UsageRights();

Enumeration en = request.getParameterNames();

String submittedData = request.getParameter("jcr:data");

System.out.println("The submitted data is "+submittedData);

org.w3c.dom.Document submittedXml = w3cDocumentFromStrng(submittedData);

String formFill = submittedXml.getElementsByTagName("formfill").item(0).getTextContent();

usageRights.setEnabledFormFillIn(Boolean.valueOf(submittedXml.getElementsByTagName("formfill").item(0).getTextContent()));

usageRights.setEnabledComments(Boolean.valueOf(submittedXml.getElementsByTagName("comments").item(0).getTextContent()));

usageRights.setEnabledEmbeddedFiles(Boolean.valueOf(submittedXml.getElementsByTagName("attachments").item(0).getTextContent()));

usageRights.setEnabledDigitalSignatures(Boolean.valueOf(submittedXml.getElementsByTagName("digitalsignatures").item(0).getTextContent()));

String attachmentPath = submittedXml.getElementsByTagName("attachmentpath").item(0).getTextContent();

System.out.println("The attachmentPath "+attachmentPath);

Node pdfNode = getResolver.getFormsServiceResolver().getResource(attachmentPath).adaptTo(Node.class);

javax.jcr.Node jcrContent = null;

try {

jcrContent = pdfNode.getNode("jcr:content");

System.out.println("The jcr content node path is " + jcrContent.getPath());

} catch (RepositoryException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

try {

InputStream is = jcrContent.getProperty("jcr:data").getBinary().getStream();

Session jcrSession = getResolver.getFormsServiceResolver().adaptTo(Session.class);

Document documentToReaderExtend = new Document(is);

documentToReaderExtend = applyRights.applyUsageRights(documentToReaderExtend,usageRights);

documentToReaderExtend.copyToFile(new File("c:\\scrap\\doctore.pdf"));

InputStream fileInputStream = documentToReaderExtend.getInputStream();

response.setContentType("application/pdf");

response.addHeader("Content-Disposition", "attachment; filename=AemFormsRocks.pdf");

response.setContentLength((int) fileInputStream.available());

OutputStream responseOutputStream = response.getOutputStream();

int bytes;

while ((bytes = fileInputStream.read()) != -1) {

responseOutputStream.write(bytes);

}

responseOutputStream.flush();

responseOutputStream.close();

documentToReaderExtend.close();

} catch (ValueFormatException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (PathNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (RepositoryException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

while(en.hasMoreElements())

{

System.out.println("The parameter name is "+en.nextElement());

}

}

}

Avatar

Avatar

brandonl8713581

Avatar

brandonl8713581

brandonl8713581

15-08-2019

Thanks! Much appreciated

Avatar

Avatar

brandonl8713581

Avatar

brandonl8713581

brandonl8713581

15-08-2019

Can this be done on a OSGI server as well?