Generate PDF documents using output service
- Applies to:
- Experience Manager as a Cloud Service
- Topics:
- Output Service
CREATED FOR:
- Beginner
- Intermediate
- Developer
AEM Forms as a Cloud Service
The Output service is an OSGi service that is part of AEM Document Services. It supports various output formats and design features of AEM Forms Designer. The Output service converts XFA templates and XML data to generate print documents in different formats.
The Output service in AEM Forms as a Cloud Service closely resembles the one in AEM Forms 6.5, so if you’re familiar with using the Output service in AEM Forms 6.5, transitioning to AEM Forms as a Cloud Service should be straightforward.
With the Output service, you can create applications that allow you to:
- Generate final form documents by populating template files with XML data.
- Generate output forms in various formats, including non-interactive PDF, PostScript, PCL, and ZPL print streams.
- Generate print PDFs from XFA form PDFs.
- Generate PDF, PostScript, PCL, and ZPL documents in bulk by merging multiple sets of data with supplied templates.
This service is designed to be used within the context of an AEM Forms as a Cloud Service instance. The following code snippet generates a PDF document in a servlet using the OutputService
.
import com.adobe.fd.output.api.OutputService;
import com.adobe.fd.output.api.PDFOutputOptions;
import com.adobe.fd.output.api.AcrobatVersion;
import com.adobe.aemfd.docmanager.Document;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.api.servlets.SlingServletPaths;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@Component(service = Servlet.class,
property = {
"sling.servlet.methods=" + HttpConstants.METHOD_POST,
"sling.servlet.paths=/bin/generateStatement"
})
public class GenerateStatementServlet extends SlingAllMethodsServlet {
@Reference
private OutputService outputService;
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
// Access the submitted form data
String formData = request.getParameter("formData");
// Define the XDP template document
String templateName = "/content/dam/formsanddocuments/adobe/statement.xdp";
Document xdpDocument = new Document(templateName);
// Set the PDF output options
PDFOutputOptions pdfOutputOptions = new PDFOutputOptions();
pdfOutputOptions.setAcrobatVersion(AcrobatVersion.Acrobat_10);
// Create the submitted data document from the form data
InputStream inputStream = new ByteArrayInputStream(formData.getBytes(StandardCharsets.UTF_8));
Document submittedData = new Document(inputStream);
// Use the output service to generate the PDF output
Document generatedPDF = outputService.generatePDFOutput(xdpDocument, submittedData, pdfOutputOptions);
// Process the generated PDF as per your use case
}
}
Experience Manager
- Overview
- Playlists
- Introduction to AEM as a Cloud Service
- Experience Cloud integrations
- Underlying Technology
- Edge Delivery Services
- Cloud Manager
- Local Development Environment Setup
- Developing
- Debugging AEM
- AEM APIs
- Content Delivery
- Caching
- Accessing AEM
- Authentication
- Advanced Networking
- Security
- AEM Eventing
- Migration
- Content Transfer Tool
- Bulk Import of assets
- Moving to AEM as a Cloud Service
- Cloud Acceleration Manager
- Content Fragments
- Forms
- Developing for Forms as a Cloud Service
- 1 - Getting started
- 2 - Install IntelliJ
- 3 - Setup Git
- 4 - Sync IntelliJ with AEM
- 5 - Build a form
- 6 - Custom Submit Handler
- 7 - Registering servlet using resource type
- 8 - Enable Forms Portal Components
- 9 - Include Cloud Services and FDM
- 10 - Context aware cloud configuration
- 11 - Push to Cloud Manager
- 12 - Deploy to development environment
- 13 - Updating maven archetype
- Create Adaptive Form
- Custom submit service with headless form
- Create address block component
- Create clickable image component
- AEM Forms and Analytics
- Creating Countries Dropdown Component
- Creating Button Variations
- Using vertical tabs
- Using output and forms service
- Document Generation in AEM Forms CS
- Using Forms Document Services API
- Document Generation using Batch API
- PDF Manipulation in Forms CS
- Integrate with Marketo
- Store Form Submissions with Blob Index Tags
- Prefill core component based form
- Azure Portal Storage
- Save and Resume form filling
- Create Review Workflow
- Acrobat Sign with AEM Forms
- Integrate with Microsoft Power Automate
- Integrate with Microsoft Dynamics
- Integrate with Salesforce
- Store form submissions in one drive and sharepoint
- Developing for Forms as a Cloud Service
- Asset Compute Extensibility
- Multi-step Tutorials
- Expert Resources