Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PDFAConformanceTestCase.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render.pdf;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import org.junit.Test;
  24. import org.xml.sax.SAXException;
  25. import static org.junit.Assert.fail;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.events.EventChecker;
  28. import org.apache.fop.pdf.PDFAMode;
  29. import org.apache.fop.pdf.PDFConformanceException;
  30. import org.apache.fop.svg.SVGEventProducer;
  31. /**
  32. * Tests PDF/A-1 functionality.
  33. */
  34. public class PDFAConformanceTestCase extends BasePDFTest {
  35. public PDFAConformanceTestCase() throws SAXException, IOException {
  36. super(getDefaultConfFile());
  37. }
  38. private File foBaseDir = new File("test/xml/pdf-a");
  39. private boolean dumpPDF = Boolean.getBoolean("PDFAConformanceTestCase.dumpPDF");
  40. /** create an FOUserAgent for our tests
  41. * @return an initialized FOUserAgent
  42. * */
  43. protected FOUserAgent getUserAgent() {
  44. final FOUserAgent userAgent = fopFactory.newFOUserAgent();
  45. userAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
  46. return userAgent;
  47. }
  48. /**
  49. * Test exception when PDF/A-1 is enabled and everything is as it should.
  50. * @throws Exception if the test fails
  51. */
  52. @Test
  53. public void testAllOk() throws Exception {
  54. File foFile = new File(foBaseDir, "minimal-pdf-a.fo");
  55. convertFO(foFile, getUserAgent(), dumpPDF);
  56. }
  57. /**
  58. * Test exception when PDF/A-1 is enabled together with encryption.
  59. * @throws Exception if the test fails
  60. */
  61. @Test(expected = PDFConformanceException.class)
  62. public void testNoEncryption() throws Exception {
  63. final FOUserAgent ua = getUserAgent();
  64. ua.getRendererOptions().put("owner-password", "mypassword"); //To enabled encryption
  65. File foFile = new File(foBaseDir, "minimal-pdf-a.fo");
  66. convertFO(foFile, ua, dumpPDF);
  67. }
  68. /**
  69. * Test exception when PDF/A-1 is enabled and a font is used which is not embedded.
  70. * @throws Exception if the test fails
  71. */
  72. @Test
  73. public void testFontNotEmbedded() throws Exception {
  74. File foFile = new File(foBaseDir, "base14-font.fo");
  75. try {
  76. convertFO(foFile, getUserAgent(), dumpPDF);
  77. fail("Expected PDFConformanceException. PDF/A-1 wants all fonts embedded.");
  78. } catch (PDFConformanceException e) {
  79. //Good!
  80. }
  81. }
  82. /**
  83. * Test exception when PDF/A-1 is enabled and images.
  84. * @throws Exception if the test fails
  85. */
  86. @Test
  87. public void testImages() throws Exception {
  88. File foFile = new File(foBaseDir, "with-rgb-images.fo");
  89. convertFO(foFile, getUserAgent(), dumpPDF);
  90. foFile = new File(foBaseDir, "with-cmyk-images.fo");
  91. try {
  92. convertFO(foFile, getUserAgent(), dumpPDF);
  93. fail("Expected PDFConformanceException."
  94. + " PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
  95. } catch (PDFConformanceException e) {
  96. //Good!
  97. }
  98. }
  99. @Test
  100. public void svgTransparency() throws Exception {
  101. Map<String, Object> params = new HashMap<String, Object>();
  102. params.put("pdfProfile", PDFAMode.PDFA_1B);
  103. EventChecker eventChecker = new EventChecker(SVGEventProducer.class.getName()
  104. + ".transparencyIgnored", params);
  105. FOUserAgent ua = getUserAgent();
  106. ua.getEventBroadcaster().addEventListener(eventChecker);
  107. File foFile = new File(foBaseDir, "svg-transparency.fo");
  108. convertFO(foFile, ua, dumpPDF);
  109. eventChecker.end();
  110. }
  111. }