Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PDFUATestCase.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.pdf;
  19. import java.awt.geom.Rectangle2D;
  20. import java.io.ByteArrayInputStream;
  21. import java.io.ByteArrayOutputStream;
  22. import java.io.IOException;
  23. import java.util.Collection;
  24. import java.util.Iterator;
  25. import org.junit.Assert;
  26. import org.junit.Test;
  27. import org.apache.xmlgraphics.util.QName;
  28. import org.apache.xmlgraphics.xmp.Metadata;
  29. import org.apache.fop.render.pdf.PDFContentGenerator;
  30. public class PDFUATestCase {
  31. @Test
  32. public void testXMP() throws IOException {
  33. PDFDocument doc = new PDFDocument("");
  34. doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
  35. Metadata metadata = PDFMetadata.createXMPFromPDFDocument(doc);
  36. StringBuilder sb = new StringBuilder();
  37. Iterator i = metadata.iterator();
  38. while (i.hasNext()) {
  39. QName k = (QName) i.next();
  40. sb.append(k + ": " + metadata.getProperty(k).getValue() + "\n");
  41. }
  42. String s = sb.toString();
  43. Assert.assertTrue(s, s.contains("pdfuaid:part: 1"));
  44. }
  45. @Test
  46. public void testPDF() throws IOException {
  47. PDFDocument doc = new PDFDocument("");
  48. doc.getRoot().makeTagged();
  49. doc.getRoot().setStructTreeRoot(new PDFStructTreeRoot(null));
  50. doc.getInfo().setTitle("title");
  51. doc.getProfile().setPDFUAMode(PDFUAMode.PDFUA_1);
  52. PDFResources resources = new PDFResources(doc);
  53. doc.addObject(resources);
  54. PDFResourceContext context = new PDFResourceContext(resources);
  55. ByteArrayOutputStream out = new ByteArrayOutputStream();
  56. PDFContentGenerator gen = new PDFContentGenerator(doc, out, context);
  57. Rectangle2D.Float f = new Rectangle2D.Float();
  58. PDFPage page = new PDFPage(resources, 0, f, f, f, f);
  59. doc.addImage(context, new BitmapImage("", 1, 1, new byte[0], null));
  60. doc.registerObject(page);
  61. gen.flushPDFDoc();
  62. doc.outputTrailer(out);
  63. Collection<StringBuilder> objs = PDFLinearizationTestCase.readObjs(
  64. new ByteArrayInputStream(out.toByteArray())).values();
  65. Assert.assertTrue(getObj(objs, "/Type /Catalog").contains("/ViewerPreferences << /DisplayDocTitle true >>"));
  66. }
  67. private String getObj(Collection<StringBuilder> objs, String x) {
  68. for (StringBuilder s : objs) {
  69. if (s.toString().contains(x)) {
  70. return s.toString();
  71. }
  72. }
  73. return null;
  74. }
  75. }