Hello,
I'm trying to run the code underneath, but it fails with the error:
Java Code:
Exception in thread "main" java.lang.ClassCastException: com.itextpdf.text.Document cannot be cast to org.w3c.dom.Document
Here's the actual code.
It seems that I'm combining two different Document classes, but I don't know how to solve it.
If my code is totally bogus, but you can help me out with a small example how to generate a PDF/A1-A file (--> thus tagged with XMP metadata such as in the "DublinCoreSchema") having as source an XML file and as layout a JasperReports template... I'd be very very happy too

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;


import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRPdfExporterPa rameter;
import net.sf.jasperreports.engine.query.JRXPathQueryExec uterFactory;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.engine.util.JRXmlUtils;


import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.xml.xmp.DublinCoreSchema;
import com.itextpdf.text.xml.xmp.XmpArray;
import com.itextpdf.text.xml.xmp.XmpSchema;
import com.itextpdf.text.xml.xmp.XmpWriter;


public class PDFA1A_v2 {

public static final String OUTPUT_PDF_FILE = "C:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/output/XMP_Tagged_BTF_v1.pdf";
public static final String REPORT_TEMPLATE = "C:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/templates/BTF/BTF.jasper";

public static final String REPORT_OUTPUT_PATH = "c:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/output/";
public static final String ICC_PROFILE = "c:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/data/srgb.profile";

public void createPdf(String filename) throws IOException, DocumentException, Exception {

Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUT_PDF_FILE));
ByteArrayOutputStream os = new ByteArrayOutputStream();

//Create instance to hold DublinCoreSchema tags
XmpWriter xmp = new XmpWriter(os);
XmpSchema dc = new com.itextpdf.text.xml.xmp.DublinCoreSchema();

//Create tag for DublinCoreSchema instance
XmpArray subject = new XmpArray(XmpArray.UNORDERED);
//Add values to the created tag of the DublinCoreSchema instance
subject.add("Subject.tagValue1");
subject.add("Subject.tagValue2");
//Assign the tag and the values to the official DublinCoreSchema tag "SUBJECT"
dc.setProperty(DublinCoreSchema.SUBJECT, subject);
xmp.addRdfDescription(dc);



xmp.close();
writer.setXmpMetadata(os.toByteArray());


Map<String, Object> params = new HashMap<String, Object>();
JRXmlUtils.parse(JRLoader.getLocationInputStream(" C:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/data/InputData_BTF.xml"));


params.put("SUBREPORT_DIR","C:/Users/maartenvd/eclipse/Jasper-PDFA1A-Generation/templates/ResultReporting/SingleOrderReport/");
System.out.println("Report template used: " + REPORT_TEMPLATE);
System.out.println("Report output path used: " + REPORT_OUTPUT_PATH);
System.out.println("Report ICC profile used: " + ICC_PROFILE);
params.put(JRXPathQueryExecuterFactory.PARAMETER_X ML_DATA_DOCUMENT, document);
params.put(JRParameter.REPORT_LOCALE, Locale.US);

JasperFillManager.fillReportToFile(REPORT_TEMPLATE , params);


byte[] reportInBytes = generateReport(params, new File(REPORT_TEMPLATE));
FileUtility.saveFile(reportInBytes, REPORT_OUTPUT_PATH, "PDFA1A_OutputJava.pdf");

}

public static byte[] generateReport(Map reportParameters, File reportTemplate) throws FileNotFoundException,
JRException
{

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
InputStream inputStream = new FileInputStream(reportTemplate);

//JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, reportParameters, new JREmptyDataSource());
JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, reportParameters);

// report exporter settings
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_P RINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_S TREAM, outputStream);

// PDF/A special parameters
exporter.setParameter(JRPdfExporterParameter.IS_TA GGED, Boolean.TRUE);
exporter.setParameter(JRPdfExporterParameter.PDFA_ CONFORMANCE, JRPdfExporterParameter.PDFA_CONFORMANCE_1A);
exporter.setParameter(JRPdfExporterParameter.PDFA_ ICC_PROFILE_PATH, ICC_PROFILE);

exporter.exportReport();

return outputStream.toByteArray();
}

public static void main(String[] args) throws Exception {
PDFA1A_v2 pdfA1A = new PDFA1A_v2();
pdfA1A.createPdf(OUTPUT_PDF_FILE);
}
}
Any help is higly appreciated!
Kind regards,
Maarten