Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TestPPTX2PNG.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.xslf.usermodel;
  20. import static java.util.Arrays.asList;
  21. import static org.junit.Assume.assumeFalse;
  22. import java.io.File;
  23. import java.util.ArrayList;
  24. import java.util.Collection;
  25. import java.util.List;
  26. import java.util.function.Function;
  27. import java.util.stream.Collectors;
  28. import java.util.stream.Stream;
  29. import org.apache.poi.POIDataSamples;
  30. import org.apache.poi.xslf.util.PPTX2PNG;
  31. import org.junit.BeforeClass;
  32. import org.junit.Test;
  33. import org.junit.runner.RunWith;
  34. import org.junit.runners.Parameterized;
  35. import org.junit.runners.Parameterized.Parameter;
  36. import org.junit.runners.Parameterized.Parameters;
  37. /**
  38. * Test class for testing PPTX2PNG utility which renders .ppt and .pptx slideshows
  39. */
  40. @SuppressWarnings("ConstantConditions")
  41. @RunWith(Parameterized.class)
  42. public class TestPPTX2PNG {
  43. private static boolean xslfOnly;
  44. private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
  45. private static final File basedir = null;
  46. private static final String files =
  47. "bug64693.pptx, 53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, " +
  48. "backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx," +
  49. "customGeo.pptx, customGeo.ppt, wrench.emf, santa.wmf, missing-moveto.ppt";
  50. @BeforeClass
  51. public static void checkHslf() {
  52. try {
  53. Class.forName("org.apache.poi.hslf.usermodel.HSLFSlideShow");
  54. } catch (Exception e) {
  55. xslfOnly = true;
  56. }
  57. }
  58. // use filename instead of File object to omit full pathname in test name
  59. @Parameter
  60. public String pptFile;
  61. @Parameters(name="{0}")
  62. public static Collection<String> data() {
  63. Function<String, Stream<String>> fun = (basedir == null) ? Stream::of :
  64. (f) -> Stream.of(basedir.listFiles(p -> p.getName().matches(f))).map(File::getName);
  65. return Stream.of(files.split(", ?")).flatMap(fun).collect(Collectors.toList());
  66. }
  67. @Test
  68. public void render() throws Exception {
  69. assumeFalse("ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run", xslfOnly && pptFile.matches(".*\\.(ppt|emf|wmf)$"));
  70. // bug64693.pptx
  71. final List<String> args = new ArrayList<>(asList(
  72. "-format", "null", // png,gif,jpg,svg or null for test
  73. "-slide", "-1", // -1 for all
  74. "-outdir", new File("build/tmp/").getCanonicalPath(),
  75. "-outpat", "${basename}-${slideno}-${ext}.${format}",
  76. // "-dump", new File("build/tmp/", pptFile+".json").getCanonicalPath(),
  77. "-dump", "null",
  78. "-quiet",
  79. "-fixside", "long",
  80. "-scale", "800"
  81. ));
  82. if ("bug64693.pptx".equals(pptFile)) {
  83. args.addAll(asList(
  84. "-charset", "GBK"
  85. ));
  86. }
  87. args.add((basedir == null ? samples.getFile(pptFile) : new File(basedir, pptFile)).getAbsolutePath());
  88. PPTX2PNG.main(args.toArray(new String[0]));
  89. }
  90. }