PdfACopy extends PdfCopy { @Override public void addDocument(PdfReader reader) throws DocumentException, IOException { checkPdfAInfo(reader); super.addDocument(reader); } PdfACopy(Document document, OutputStream os, PdfAConformanceLevel conformanceLevel); @Override void addDocument(PdfReader reader); @Override void addPage(PdfImportedPage iPage); @Override PageStamp createPageStamp(PdfImportedPage iPage); @Override void setOutputIntents(final String outputConditionIdentifier, final String outputCondition, final String registryName, final String info, final ICC_Profile colorProfile); @Override boolean setOutputIntents(PdfReader reader, boolean checkExistence); @Override void close();  }
@Test public void testMergeFields2() throws DocumentException, IOException { String f1 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-1a.pdf"; String f2 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-1a-2.pdf"; String f3 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-1b.pdf"; OutputStream outputPdfStream = new ByteArrayOutputStream(); Document document = new Document(); PdfACopy copy = new PdfACopy(document, outputPdfStream, PdfAConformanceLevel.PDF_A_1A); copy.setMergeFields(); copy.createXmpMetadata(); copy.setTagged(); document.open(); document.addLanguage("en-US"); boolean exceptionThrown = false; try { for (String f : new String[]{f1, f2, f3}) { PdfReader reader = new PdfReader(f); copy.addDocument(reader); } } catch (PdfAConformanceException e) { if (e.getMessage().contains("Incompatible PDF/A conformance level")) exceptionThrown = true; } if (!exceptionThrown) junit.framework.Assert.fail("PdfAConformanceException should be thrown."); }
@Test public void testMergeFields3() throws DocumentException, IOException { String f1 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-1a.pdf"; String f2 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-2a.pdf"; OutputStream outputPdfStream = new ByteArrayOutputStream(); Document document = new Document(); PdfACopy copy = new PdfACopy(document, outputPdfStream, PdfAConformanceLevel.PDF_A_1A); copy.setMergeFields(); copy.createXmpMetadata(); copy.setTagged(); document.open(); document.addLanguage("en-US"); boolean exceptionThrown = false; try { for (String f : new String[]{f1, f2}) { PdfReader reader = new PdfReader(f); copy.addDocument(reader); } } catch (PdfAConformanceException e) { if (e.getMessage().contains("Different PDF/A version")) exceptionThrown = true; } if (!exceptionThrown) junit.framework.Assert.fail("PdfAConformanceException should be thrown."); }
@Test public void testMergeFields4() throws DocumentException, IOException { String f1 = "./src/test/resources/com/itextpdf/text/pdf/copy/pdfa-1a.pdf"; String f2 = "./src/test/resources/com/itextpdf/text/pdf/copy/source16.pdf"; OutputStream outputPdfStream = new ByteArrayOutputStream(); Document document = new Document(); PdfACopy copy = new PdfACopy(document, outputPdfStream, PdfAConformanceLevel.PDF_A_1B); copy.setMergeFields(); copy.createXmpMetadata(); copy.setTagged(); document.open(); document.addLanguage("en-US"); boolean exceptionThrown = false; try { for (String f : new String[]{f1, f2}) { PdfReader reader = new PdfReader(f); copy.addDocument(reader); } } catch (PdfAConformanceException e) { if (e.getMessage().contains("Only PDF/A documents can be added in PdfACopy")) exceptionThrown = true; } if (!exceptionThrown) junit.framework.Assert.fail("PdfAConformanceException should be thrown."); }