You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PDFAConformanceTestCase.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 static org.junit.Assert.fail;
  20. import java.io.File;
  21. import org.apache.fop.apps.FOUserAgent;
  22. import org.apache.fop.pdf.PDFConformanceException;
  23. import org.junit.Test;
  24. /**
  25. * Tests PDF/A-1 functionality.
  26. */
  27. public class PDFAConformanceTestCase extends BasePDFTest {
  28. private File foBaseDir = new File("test/xml/pdf-a");
  29. private boolean dumpPDF = Boolean.getBoolean("PDFAConformanceTestCase.dumpPDF");
  30. /** create an FOUserAgent for our tests
  31. * @return an initialized FOUserAgent
  32. * */
  33. protected FOUserAgent getUserAgent() {
  34. final FOUserAgent userAgent = fopFactory.newFOUserAgent();
  35. userAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
  36. return userAgent;
  37. }
  38. /**
  39. * Test exception when PDF/A-1 is enabled and everything is as it should.
  40. * @throws Exception if the test fails
  41. */
  42. @Test
  43. public void testAllOk() throws Exception {
  44. File foFile = new File(foBaseDir, "minimal-pdf-a.fo");
  45. convertFO(foFile, getUserAgent(), dumpPDF);
  46. }
  47. /**
  48. * Test exception when PDF/A-1 is enabled together with encryption.
  49. * @throws Exception if the test fails
  50. */
  51. @Test
  52. public void testNoEncryption() throws Exception {
  53. final FOUserAgent ua = getUserAgent();
  54. ua.getRendererOptions().put("owner-password", "mypassword"); //To enabled encryption
  55. File foFile = new File(foBaseDir, "minimal-pdf-a.fo");
  56. try {
  57. convertFO(foFile, ua, dumpPDF);
  58. fail("Expected PDFConformanceException. PDF/A-1 and PDF encryption don't go together.");
  59. } catch (PDFConformanceException e) {
  60. //Good!
  61. }
  62. }
  63. /**
  64. * Test exception when PDF/A-1 is enabled and a font is used which is not embedded.
  65. * @throws Exception if the test fails
  66. */
  67. @Test
  68. public void testFontNotEmbedded() throws Exception {
  69. File foFile = new File(foBaseDir, "base14-font.fo");
  70. try {
  71. convertFO(foFile, getUserAgent(), dumpPDF);
  72. fail("Expected PDFConformanceException. PDF/A-1 wants all fonts embedded.");
  73. } catch (PDFConformanceException e) {
  74. //Good!
  75. }
  76. }
  77. /**
  78. * Test exception when PDF/A-1 is enabled and images.
  79. * @throws Exception if the test fails
  80. */
  81. @Test
  82. public void testImages() throws Exception {
  83. File foFile = new File(foBaseDir, "with-rgb-images.fo");
  84. convertFO(foFile, getUserAgent(), dumpPDF);
  85. foFile = new File(foBaseDir, "with-cmyk-images.fo");
  86. try {
  87. convertFO(foFile, getUserAgent(), dumpPDF);
  88. fail("Expected PDFConformanceException."
  89. + " PDF/A-1 does not allow mixing DeviceRGB and DeviceCMYK.");
  90. } catch (PDFConformanceException e) {
  91. //Good!
  92. }
  93. }
  94. }