How to render PDF/A

AlexanderWillet
Employee
15-10-2015

Hi,

we would like to render a PDF/A out of an xdp template and some xml formdata. The OutputService.generatePDFOutput(xdp, xml-data, PDFOutputOptions) should be the right api to do this. The specific adjustments to get a PDF/A should be handed over within the PDFOutputOptions object I assume. 

The former LiveCycle api had a similar service but the paramerters are different. It supported settings like:

  • TransformationFormat.PDFA
  • setPDFARevisionNumber(PDFARevisionNumber.Revision_1)
  • setPDFAConformance(PDFAConformance.B) 

In the PDFOutputOptions I'm missing settings like that.

Can someone provide me with a code snippet or point me to some sample that does PDF/A rendering with the new AEM6 forms?

Thank's for any help on this!

Alex

Accepted Solutions (1)

Accepted Solutions (1)

nitinn18425437 15-10-2015

Hi Alex,

In order to create PDF/A document you need to render regular PDF using OutputService.generatePDFOutput(xdp,xml-data,PDFOutputOptions) and convert resulting PDF to PDF/A using AssemblerService.toPDFA method.

http://helpx.adobe.com/aem-forms/6/javadocs/com/adobe/fd/assembler/service/AssemblerService.html#toP..., com.adobe.fd.assembler.client.PDFAConversionOptionSpec)

 

Thanks

Nitin

Answers (14)

Answers (14)

sebastian_wilhe 15-10-2015

Here is the final example code, after all corrections:

/* * converts existing PDF file to PDF/A-1b format */ private Document convertToPDFA(Document inputPDF, String xmpFileName) { try { PDFAConversionOptionSpec conversionSpec = new  PDFAConversionOptionSpec(); conversionSpec.setLogLevel("FINE"); conversionSpec.setResultLevel(PDFAConversionOptionSpec.ResultLevel.DETAILED); conversionSpec.setCompliance(PDFAConversionOptionSpec.Compliance.PDFA_1B); conversionSpec.setSignatures(PDFAConversionOptionSpec.Signatures.ARCHIVE_AS_NEEDED); conversionSpec.setColorSpace(PDFAConversionOptionSpec.ColorSpace.S_RGB); if (xmpFileName != null) { // Add PDFA Converter Schema String schemaPath = xmpFileName; List<Document> metadataSchemaExtensions = new ArrayList<Document>(); Document schemaDoc = new Document(new File(schemaPath)); metadataSchemaExtensions.add(schemaDoc); conversionSpec.setMetadataSchemaExtensions(metadataSchemaExtensions); //conversionSpec.setRemoveInvalidXMPProperties(true); } PDFAConversionResult pdfaResult = assemblerService.toPDFA(inputPDF, conversionSpec); Document pdfa = (pdfaResult != null) ? pdfaResult.getPDFADocument() : null; return pdfa; } catch (ConversionException e) { RenderServlet.LOG.debug(e.getClass().getName() + ": " + e.getLocalizedMessage()); e.printStackTrace(); this.logStackTrace(e); } return null; }
nitinn18425437 15-10-2015

Hi Alex, Sebastian,

I think the issue is that the xmp file resides on file system and in the code 

Document schemaDoc = new Document(schemaPath);

schemeDoc is being created using string argument constructor. This assumes the files is in repository. In order to specify a file which resides on files system use constructor with java.io.File argument as in

Document schemaDoc = new Document(new java.io.File(schemaPath));

 

Thanks

Nitin

sharoon23
Employee
15-10-2015

Hi Sebastian,

I could not make out much from this stack trace. Can you please attach the collateral with which you are facing this exception. I will have a look at it and reply accordingly.

Regards,

Sufyan

sebastian_wilhe 15-10-2015
org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:89) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:55) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:298) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:115) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:76) org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:49) org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501) org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229) org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428) org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020) org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) org.eclipse.jetty.server.Server.handle(Server.java:370) org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494) org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971) org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033) org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667) org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) java.lang.Thread.run(Unknown Source)
sebastian_wilhe 15-10-2015

Here the stack trace:

com.adobe.fd.assembler.client.ConversionException: AEM-ASM-S02-001: The document named "docConverter.pdf" could not be opened. com.adobe.fd.assembler.service.impl.AssemblerServiceImpl.toPDFA(AssemblerServiceImpl.java:449) osplus.dms.service.renderengine.aemforms.renderer.RenderServlet.convertToPDFA(RenderServlet.java:248) osplus.dms.service.renderengine.aemforms.renderer.RenderServlet.doGet(RenderServlet.java:176) org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268) org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:139) org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344) org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375) org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511) org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:146) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:357) com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:166) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:96) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:284) org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64) com.adobe.granite.requests.logging.impl.RequestLoggerImpl.doFilter(RequestLoggerImpl.java:124) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.cq.social.commons.security.SaferSlingPostServlet.doFilter(SaferSlingPostServlet.java:121) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl.doFilter(AuthoringUIModeServiceImpl.java:349) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:106) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.fd.core.security.internal.CurrentUserServiceImpl.doFilter(CurrentUserServiceImpl.java:121) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:295) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.livecycle.dsc.clientsdk.internal.ResourceResolverHolderFilter.doFilter(ResourceResolverHolderFilter.java:37) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:64) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.cq.social.commons.cors.CORSAuthenticationFilter.doFilter(CORSAuthenticationFilter.java:91) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:251) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.theme.impl.ThemeResolverFilter.doFilter(ThemeResolverFilter.java:76) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:74) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) osplus.dms.service.renderengine.aemforms.impl.filters.LoggingFilter.doFilter(LoggingFilter.java:40) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.cq.history.impl.HistoryRequestFilter.doFilter(HistoryRequestFilter.java:107) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter.doFilter(CanvasPageDeleteRequestFilter.java:88) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:77) com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:56) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:128) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.cq.dam.s7imaging.impl.auth.MemoryTokenAuthHandler.doFilter(MemoryTokenAuthHandler.java:156) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter.doFilter(BackgroundServletStarterFilter.java:135) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl.doFilter(ResourceResolverHelperImpl.java:81) org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60) org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:153) org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:205) org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:339) org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:300) org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:93) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:50) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:128) org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:108) org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:80) org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:46) org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:31) org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:290)
sebastian_wilhe 15-10-2015

Hi Nitin,

sorry, had some problems with the forum. First i had my former posting twice, then when I delete one, both were gone.

So here once again with the stack trace.

 

I am trying to get the PDF/A transformation running, using the following code.

try { PDFAConversionOptionSpec conversionSpec = new  PDFAConversionOptionSpec(); conversionSpec.setLogLevel("FINE"); conversionSpec.setResultLevel(PDFAConversionOptionSpec.ResultLevel.DETAILED); conversionSpec.setCompliance(PDFAConversionOptionSpec.Compliance.PDFA_1B); conversionSpec.setSignatures(PDFAConversionOptionSpec.Signatures.ARCHIVE_AS_NEEDED); conversionSpec.setColorSpace(PDFAConversionOptionSpec.ColorSpace.S_RGB); // Add PDFA Converter Schema String schemaPath = "C:/tmp/XMP_SCHEMA.xmp"; List<Document> metadataSchemaExtensions = new ArrayList<Document>(); Document schemaDoc = new Document(schemaPath); metadataSchemaExtensions.add(schemaDoc); conversionSpec.setMetadataSchemaExtensions(metadataSchemaExtensions); //conversionSpec.setRemoveInvalidXMPProperties(true); PDFAConversionResult pdfaResult = assemblerService.toPDFA(inputPDF, conversionSpec); Document pdfa = (pdfaResult != null) ? pdfaResult.getPDFADocument() : null; return pdfa; } catch (ConversionException e) { RenderServlet.LOG.debug(e.getClass().getName() + ": " + e.getLocalizedMessage()); e.printStackTrace(); }

If I use this with a simple flat PDF with only some text in it, I get this Exception:

com.adobe.fd.assembler.client.ConversionException: AEM-ASM-S02-001: The document named "docConverter.pdf" could not be opened.

If I do not use "setMetadataSchemaExtensions", a PDF/A document is generated, but our validation tool reports the missing schema and some other options.

How can I solve this problem or where can I find more information on this matter? Unfortionately the api docs contain nearly no explanans of any kind.

 

Thanks

Sebastian

AlexanderWillet
Employee
15-10-2015

This issue was found by Sebastian. We are working together in the same AEM Forms project.

Sebastian, could you please provide the stack trace?

sebastian_wilhe 15-10-2015

Hi,

I am trying to get the PDF/A transformation running, using the following code.

try { PDFAConversionOptionSpec conversionSpec = new  PDFAConversionOptionSpec(); conversionSpec.setLogLevel("FINE"); conversionSpec.setResultLevel(PDFAConversionOptionSpec.ResultLevel.DETAILED); conversionSpec.setCompliance(PDFAConversionOptionSpec.Compliance.PDFA_1B); conversionSpec.setSignatures(PDFAConversionOptionSpec.Signatures.ARCHIVE_AS_NEEDED); conversionSpec.setColorSpace(PDFAConversionOptionSpec.ColorSpace.S_RGB); // Add PDFA Converter Schema String schemaPath = "C:/tmp/XMP_SCHEMA.xmp"; List<Document> metadataSchemaExtensions = new ArrayList<Document>(); Document schemaDoc = new Document(schemaPath); metadataSchemaExtensions.add(schemaDoc); conversionSpec.setMetadataSchemaExtensions(metadataSchemaExtensions); //conversionSpec.setRemoveInvalidXMPProperties(true); PDFAConversionResult pdfaResult = assemblerService.toPDFA(inputPDF, conversionSpec); Document pdfa = (pdfaResult != null) ? pdfaResult.getPDFADocument() : null; return pdfa; } catch (ConversionException e) { RenderServlet.LOG.debug(e.getClass().getName() + ": " + e.getLocalizedMessage()); e.printStackTrace(); }

If I use this with a simple flat PDF with only some text in it, I get this Exception:

com.adobe.fd.assembler.client.ConversionException: AEM-ASM-S02-001: The document named "docConverter.pdf" could not be opened.

 

If I do not use "setMetadataSchemaExtensions", a PDF/A document is generated, but our validation tool reports the missing schema and some other options.

 

How can I solve this problem or where can I find more information on this matter? Unfortionately the api docs contain nearly no explanations of any kind.

Any hint welcome!

AlexanderWillet
Employee
15-10-2015

Hi Nitin,

it sounds a bit cumbersome to me to render it first and transform it afterwards. So I thought there must be some other direct way like usage of specific settings in a xci-file. But if it is the recommended way to do two calls, we are happy to go for it. 

Thank's for your quick response!

Regards

Alex