Can AEM designer be used to enable reader extension on a PDF?
Solved! Go to Solution.
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
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
Can this be done on a OSGI server as well?
Views
Replies
Total Likes
Yes, Aem forms OSGi provides reader extension capabilities as well.
Hi Mayank_Gandhi,
While using reader extension service in Adaptive form, i have set up keystore already and wrote java code to apply usage write but getting exception like below:
com.adobe.fd.docassurance.client.api.impl.DocAssuranceServiceImpl Exception while applying usage rights in DocAssuranceService
com.adobe.fd.readerextensions.client.ProcessingException: AEM-REX-001-008: Unable to apply the requested usage rights to the given document.
at com.adobe.fd.readerextensions.service.impl.ReaderExtensionsServiceImpl.applyUsageRights(ReaderExtensionsServiceImpl.java:215) [com.adobe.aemfd.adobe-aemfd-readerextensions:6.0.26]
at com.adobe.fd.docassurance.client.api.impl.DocAssuranceServiceImpl.addReaderExtensions(DocAssuranceServiceImpl.java:887) [adobe-aemfd-docassurance:6.0.50]
at com.adobe.fd.docassurance.client.api.impl.DocAssuranceServiceImpl.secureDocument(DocAssuranceServiceImpl.java:242) [adobe-aemfd-docassurance:6.0.50]
If you have any idea please help
Thanks and regards,
Ashish Saxena
Views
Replies
Total Likes
I will put out a sample on this soon
Thanks! Much appreciated
Views
Replies
Total Likes
is this what you wanted?
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());
}
}
}
Views
Replies
Total Likes
Views
Likes
Replies