Flatten XFA using pdfXFA

Tags: pdfxfa
Files: 
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2017 iText Group NV
    Authors: iText Software.
 
    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
package com.itextpdf.samples.sandbox.xfa;
 
import com.itextpdf.licensekey.XfaLicenseKey;
import com.itextpdf.samples.GenericTest;
import com.itextpdf.test.annotations.type.SampleTest;
import com.itextpdf.tool.xml.xtra.xfa.MetaData;
import com.itextpdf.tool.xml.xtra.xfa.XFAFlattener;
import com.itextpdf.tool.xml.xtra.xfa.XFAFlattenerProperties;
import com.itextpdf.tool.xml.xtra.xfa.font.XFAFontSettings;
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
 
import org.junit.experimental.categories.Category;
 
/**
 * @author Michael Demey
 */
@Category( SampleTest.class)
public class FlattenXfaDocument extends GenericTest {
    public static final String XFA = "./src/test/resources/xfa/xfa.pdf";
    public static final String DEST = "./target/test/resources/xfa/flattened.pdf";
 
    private List<String> javascriptEvents;
 
    @Override
    protected void beforeManipulatePdf() {
        XfaLicenseKey.loadLicenseFile(System.getenv("ITEXT7_LICENSEKEY") + "/all-products.xml");
 
        this.javascriptEvents = new ArrayList<>();
 
        this.javascriptEvents.add("click");
    }
 
    @Override
    protected void manipulatePdf(String dest) throws Exception {
        XFAFlattenerProperties flattenerProperties = new XFAFlattenerProperties()
                .setPdfVersion(XFAFlattenerProperties.PDF_1_7)
                .createXmpMetaData()
                .setTagged()
                .setExtractXdpConcurrently(false)
                .setMetaData(
                        new MetaData()
                            .setAuthor("iText Samples")
                            .setLanguage("EN")
                            .setSubject("Showing off our flattening skills")
                            .setTitle("Flattened XFA"));
 
        XFAFlattener xfaf = new XFAFlattener()
                .setFontSettings(new XFAFontSettings().setEmbedExternalFonts(true))
                .setExtraEventList(this.javascriptEvents)
                .setFlattenerProperties(flattenerProperties)
                .setViewMode(XFAFlattener.ViewMode.SCREEN);
 
 
        xfaf.flatten(new FileInputStream(XFA), new FileOutputStream(dest));
    }
}
File nameRaw URLUpdated
FlattenXfaDocument.javaFlattenXfaDocument.java2017-03-02 7:38 pm
Resources: 
File nameRaw URLUpdated
xfa.pdfxfa.pdf2017-03-02 7:40 pm
Results: 
File nameRaw URLUpdated
cmp_flattened.pdfcmp_flattened.pdf2017-03-02 7:41 pm