Package flex.samples.pdfgen_contact

Source Code of flex.samples.pdfgen_contact.XDPXFAService

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package flex.samples.pdfgen_contact;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Document;

import flex.acrobat.pdf.XDPXFAHelper;
import flex.messaging.FlexContext;
import flex.messaging.FlexSession;
import flex.messaging.util.UUIDUtils;

public class XDPXFAService
{
    public XDPXFAService()
    {
    }

    public Object generatePDF(Document dataset) throws IOException
    {
        // Open shell XDP containing XFA template based on servlet context (in this case webapp root)
        String source = FlexContext.getServletContext().getRealPath("/pdfgen_contact/contact.xdp");
        XDPXFAHelper helper = new XDPXFAHelper();
        helper.open(source);

        // Import XFA dataset
        helper.importDataset(dataset);

        // Save new PDF as a byte array in the current session
        byte[] bytes = helper.saveToByteArray();
        String uuid = UUIDUtils.createUUID();
        FlexSession session = FlexContext.getFlexSession();
        session.setAttribute(uuid, bytes);

        // Close any resources
        helper.close();

        HttpServletRequest req = FlexContext.getHttpRequest();
        String contextRoot = "/lcds-samples";
        if (req != null)
            contextRoot = req.getContextPath();

        return contextRoot + "/dynamic-pdf?id=" + uuid + "&;jsessionid=" + session.getId();
    }
}
TOP

Related Classes of flex.samples.pdfgen_contact.XDPXFAService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.