You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/11/02 23:56:27 UTC
svn commit: r1883074 - in /poi: site/src/documentation/content/xdocs/
site/src/documentation/content/xdocs/components/
site/src/documentation/content/xdocs/components/slideshow/ trunk/
trunk/src/java/org/apache/poi/sl/draw/ trunk/src/ooxml/java/org/apa...
Author: kiwiwings
Date: Mon Nov 2 23:56:27 2020
New Revision: 1883074
URL: http://svn.apache.org/viewvc?rev=1883074&view=rev
Log:
#64867 - Provide PDF rendering with PPTX2PNG
Added:
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java (with props)
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java (with props)
Modified:
poi/site/src/documentation/content/xdocs/changes.xml
poi/site/src/documentation/content/xdocs/components/index.xml
poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml
poi/site/src/documentation/content/xdocs/site.xml
poi/trunk/build.xml
poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/OutputFormat.java
poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
Modified: poi/site/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Mon Nov 2 23:56:27 2020
@@ -112,6 +112,7 @@
<action type="fix" fixes-bug="64773" context="POI_Overall">Visual signatures for .xlsx/.docx</action>
<action type="fix" fixes-bug="64817" context="POIFS">Fix issue in testXLSXinPPT</action>
<action type="fix" fixes-bug="github-193" context="SS_Common">Change TRUNC implementation to use MathX</action>
+ <action type="add" fixes-bug="64867" context="SL_Common">Provide PDF rendering with PPTX2PNG</action>
</actions>
</release>
Modified: poi/site/src/documentation/content/xdocs/components/index.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/components/index.xml?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/components/index.xml (original)
+++ poi/site/src/documentation/content/xdocs/components/index.xml Mon Nov 2 23:56:27 2020
@@ -313,7 +313,11 @@
For SVG support:
<a href="https://search.maven.org/#search|gav|1|g:org.apache.xmlgraphics AND a:batik-all">batik-all</a>,
<a href="https://search.maven.org/#search|gav|1|g:xml-apis AND a:xml-apis-ext">xml-apis-ext</a>,
- <a href="https://search.maven.org/#search|gav|1|g:org.apache.xmlgraphics AND a:xmlgraphics-commons">xmlgraphics-commons</a>
+ <a href="https://search.maven.org/#search|gav|1|g:org.apache.xmlgraphics AND a:xmlgraphics-commons">xmlgraphics-commons</a><br/>
+ For PDF support:
+ <a href="https://search.maven.org/#search|gav|1|g:org.apache.pdfbox AND a:pdfbox">pdfbox</a>,
+ <a href="https://search.maven.org/#search|gav|1|g:org.apache.pdfbox AND a:fontbox">fontbox</a>,
+ <a href="https://search.maven.org/#search|gav|1|g:de.rototor.pdfbox AND a:graphics2d">rototor graphics2d</a>
</td>
<td>poi-ooxml-version-yyyymmdd.jar</td>
</tr>
Modified: poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml (original)
+++ poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml Mon Nov 2 23:56:27 2020
@@ -42,7 +42,7 @@
-scale <float> scale factor
-fixSide <side> specify side (long,short,width,height) to fix - use <scale> as amount of pixels
-slide <integer> 1-based index of a slide to render
- -format <type> png,gif,jpg,svg (,null for testing)
+ -format <type> png,gif,jpg,svg,pdf (,null for testing)
-outdir <dir> output directory, defaults to origin of the ppt/pptx file
-outfile <file> output filename, defaults to "${basename}-${slideno}.${format}"
-outpat <pattern> output filename pattern, defaults to "${basename}-${slideno}.${format}"
@@ -62,7 +62,9 @@
<section>
<title>Instructions to run</title>
- <p>Download the <a href="https://ci-builds.apache.org/job/POI/job/POI-DSL-1.8/lastSuccessfulBuild/artifact/build/dist/">current nightly</a></p>
+ <p>
+ Download the <a href="https://ci-builds.apache.org/job/POI/job/POI-DSL-1.8/lastSuccessfulBuild/artifact/build/dist/">current nightly</a>
+ and for SVG/PDF the <a href="site:components/index/batikpdf">additional dependencies</a>.</p>
<p>Execute the java command (Unix-paths needs to be replaced for Windows - use "-charset" for non-western WMF/EMFs):</p>
<source>
java -cp poi-5.0.0-SNAPSHOT.jar:poi-ooxml-5.0.0-SNAPSHOT.jar:poi-ooxml-schemas-5.0.0-SNAPSHOT.jar:poi-scratchpad-5.0.0-SNAPSHOT.jar:lib/*:ooxml-lib/*:auxiliary/* org.apache.poi.xslf.util.PPTX2PNG -format png -fixside long -scale 1000 -charset GBK file.pptx
Modified: poi/site/src/documentation/content/xdocs/site.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/site.xml?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/site.xml (original)
+++ poi/site/src/documentation/content/xdocs/site.xml Mon Nov 2 23:56:27 2020
@@ -50,7 +50,9 @@ See http://xml.apache.org/forrest/linkin
<security label="Security" href="https://www.apache.org/security/"/>
</apache>
<components label="Component APIs" href="components/" tab="components">
- <index label="Overview" href="index.html"/>
+ <index label="Overview" href="index.html">
+ <batikpdf href="#components"/>
+ </index>
<javadocs label="Javadocs" href="site:javadocs"/>
<spreadsheet label="Excel (HSSF/XSSF)" href="spreadsheet/">
<index label="Overview" href="index.html"/>
Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Mon Nov 2 23:56:27 2020
@@ -294,10 +294,13 @@ under the License.
<!-- only used for signing the release - not used with the ooxml signatures -->
<dependency prefix="dsig.bouncycastle-bcpg" artifact="org.bouncycastle:bcpg-jdk15on:1.66" usage="util"/>
- <!-- svg/batik libs - not part of the distribution -->
+ <!-- svg/batik/pdf libs - not part of the distribution -->
<dependency prefix="svg.xml-apis-ext" artifact="xml-apis:xml-apis-ext:1.3.04" usage="ooxml-provided"/>
<dependency prefix="svg.xmlgraphics-commons" artifact="org.apache.xmlgraphics:xmlgraphics-commons:2.4" usage="ooxml-provided"/>
<dependency prefix="svg.batik-all" artifact="org.apache.xmlgraphics:batik-all:1.13" usage="ooxml-provided"/>
+ <dependency prefix="pdf.pdfbox" artifact="org.apache.pdfbox:pdfbox:2.0.19" usage="ooxml-provided"/>
+ <dependency prefix="pdf.fontbox" artifact="org.apache.pdfbox:fontbox:2.0.19" usage="ooxml-provided"/>
+ <dependency prefix="pdf.graphics2d" artifact="de.rototor.pdfbox:graphics2d:0.27" usage="ooxml-provided"/>
<!-- jars in the ooxml-lib directory, see the fetch-ooxml-jars target-->
<dependency prefix="ooxml.curvesapi" artifact="com.github.virtuald:curvesapi:1.06" usage="ooxml"/>
@@ -450,10 +453,17 @@ under the License.
<pathelement location="${svg.xmlgraphics-commons.jar}"/>
</path>
+ <path id="pdfbox.classpath">
+ <pathelement location="${pdf.pdfbox.jar}"/>
+ <pathelement location="${pdf.fontbox.jar}"/>
+ <pathelement location="${pdf.graphics2d.jar}"/>
+ </path>
+
<path id="ooxml.classpath">
<pathelement location="${ooxml.xsds.jar}"/>
<path refid="ooxml.base.classpath"/>
<path refid="batik.classpath"/>
+ <path refid="pdfbox.classpath"/>
</path>
<path id="ooxml.lite.verify.classpath">
@@ -712,6 +722,9 @@ under the License.
<available file="${svg.xml-apis-ext.jar}"/>
<available file="${svg.batik-all.jar}"/>
<available file="${svg.xmlgraphics-commons.jar}"/>
+ <available file="${pdf.pdfbox.jar}"/>
+ <available file="${pdf.fontbox.jar}"/>
+ <available file="${pdf.graphics2d.jar}"/>
</and>
<isset property="disconnected"/>
</or>
@@ -730,6 +743,9 @@ under the License.
<downloadfile src="${svg.batik-all.url}" dest="${svg.batik-all.jar}"/>
<downloadfile src="${svg.xml-apis-ext.url}" dest="${svg.xml-apis-ext.jar}"/>
<downloadfile src="${svg.xmlgraphics-commons.url}" dest="${svg.xmlgraphics-commons.jar}"/>
+ <downloadfile src="${pdf.pdfbox.url}" dest="${pdf.pdfbox.jar}"/>
+ <downloadfile src="${pdf.fontbox.url}" dest="${pdf.fontbox.jar}"/>
+ <downloadfile src="${pdf.graphics2d.url}" dest="${pdf.graphics2d.jar}"/>
</target>
<target name="check-svn-jars">
Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextFragment.java Mon Nov 2 23:56:27 2020
@@ -17,7 +17,9 @@
package org.apache.poi.sl.draw;
+import java.awt.Color;
import java.awt.Graphics2D;
+import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;
@@ -50,7 +52,22 @@ public class DrawTextFragment implements
if(textMode != null && textMode == Drawable.TEXT_AS_SHAPES){
layout.draw(graphics, (float)x, (float)yBaseline);
} else {
- graphics.drawString(str.getIterator(), (float)x, (float)yBaseline );
+ try {
+ graphics.drawString(str.getIterator(), (float) x, (float) yBaseline);
+ } catch (ClassCastException e) {
+ // workaround: batik issue, which expects only Color as forground color
+ replaceForgroundPaintWithBlack(str);
+ graphics.drawString(str.getIterator(), (float) x, (float) yBaseline);
+ }
+ }
+ }
+
+ private void replaceForgroundPaintWithBlack(AttributedString as) {
+ AttributedCharacterIterator iter = as.getIterator(new TextAttribute[]{TextAttribute.FOREGROUND});
+ for (char ch = iter.first();
+ ch != CharacterIterator.DONE;
+ ch = iter.next()) {
+ as.addAttribute(TextAttribute.FOREGROUND, Color.BLACK, iter.getBeginIndex(), iter.getEndIndex());
}
}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java?rev=1883074&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java Mon Nov 2 23:56:27 2020
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.util;
+
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.lang.ref.WeakReference;
+
+import javax.imageio.ImageIO;
+
+import org.apache.poi.sl.draw.Drawable;
+import org.apache.poi.util.Internal;
+
+@Internal
+public class BitmapFormat implements OutputFormat {
+ private final String format;
+ private BufferedImage img;
+ private Graphics2D graphics;
+
+ public BitmapFormat(String format) {
+ this.format = format;
+ }
+
+ @Override
+ public Graphics2D addSlide(double width, double height) {
+ img = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
+ graphics = img.createGraphics();
+ graphics.setRenderingHint(Drawable.BUFFERED_IMAGE, new WeakReference<>(img));
+ return graphics;
+ }
+
+ @Override
+ public void writeSlide(MFProxy proxy, File outFile) throws IOException {
+ if (!"null".equals(format)) {
+ ImageIO.write(img, format, outFile);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (graphics != null) {
+ graphics.dispose();
+ img.flush();
+ }
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/BitmapFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/OutputFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/OutputFormat.java?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/OutputFormat.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/OutputFormat.java Mon Nov 2 23:56:27 2020
@@ -19,23 +19,12 @@
package org.apache.poi.xslf.util;
-import java.awt.Dimension;
import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
-import java.lang.ref.WeakReference;
-import javax.imageio.ImageIO;
-
-import org.apache.batik.dom.GenericDOMImplementation;
-import org.apache.batik.svggen.SVGGraphics2D;
-import org.apache.poi.sl.draw.Drawable;
import org.apache.poi.util.Internal;
-import org.apache.poi.xslf.draw.SVGPOIGraphics2D;
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
/**
* Output formats for PPTX2PNG
@@ -43,72 +32,12 @@ import org.w3c.dom.Document;
@Internal
interface OutputFormat extends Closeable {
- Graphics2D getGraphics2D(double width, double height);
+ Graphics2D addSlide(double width, double height) throws IOException;
+
+ void writeSlide(MFProxy proxy, File outFile) throws IOException;
+
+ default void writeDocument(MFProxy proxy, File outFile) throws IOException {};
+
- void writeOut(MFProxy proxy, File outFile) throws IOException;
- class SVGFormat implements OutputFormat {
- static final String svgNS = "http://www.w3.org/2000/svg";
- private SVGGraphics2D svgGenerator;
- private final boolean textAsShapes;
-
- SVGFormat(boolean textAsShapes) {
- this.textAsShapes = textAsShapes;
- }
-
- @Override
- public Graphics2D getGraphics2D(double width, double height) {
- // Get a DOMImplementation.
- DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
-
- // Create an instance of org.w3c.dom.Document.
- Document document = domImpl.createDocument(svgNS, "svg", null);
- svgGenerator = new SVGPOIGraphics2D(document, textAsShapes);
- svgGenerator.setSVGCanvasSize(new Dimension((int)width, (int)height));
- return svgGenerator;
- }
-
- @Override
- public void writeOut(MFProxy proxy, File outFile) throws IOException {
- svgGenerator.stream(outFile.getCanonicalPath(), true);
- }
-
- @Override
- public void close() throws IOException {
- svgGenerator.dispose();
- }
- }
-
- class BitmapFormat implements OutputFormat {
- private final String format;
- private BufferedImage img;
- private Graphics2D graphics;
-
- BitmapFormat(String format) {
- this.format = format;
- }
-
- @Override
- public Graphics2D getGraphics2D(double width, double height) {
- img = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_ARGB);
- graphics = img.createGraphics();
- graphics.setRenderingHint(Drawable.BUFFERED_IMAGE, new WeakReference<>(img));
- return graphics;
- }
-
- @Override
- public void writeOut(MFProxy proxy, File outFile) throws IOException {
- if (!"null".equals(format)) {
- ImageIO.write(img, format, outFile);
- }
- }
-
- @Override
- public void close() throws IOException {
- if (graphics != null) {
- graphics.dispose();
- img.flush();
- }
- }
- }
}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java?rev=1883074&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java Mon Nov 2 23:56:27 2020
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.util;
+
+import java.awt.Graphics2D;
+import java.io.File;
+import java.io.IOException;
+
+import de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
+import org.apache.poi.util.Internal;
+
+@Internal
+public class PDFFormat implements OutputFormat {
+ private final PDDocument document;
+ private PDPageContentStream contentStream;
+ private PdfBoxGraphics2D pdfBoxGraphics2D;
+
+ public PDFFormat() {
+ document = new PDDocument();
+ }
+
+ @Override
+ public Graphics2D addSlide(double width, double height) throws IOException {
+ PDPage page = new PDPage(new PDRectangle((float) width, (float) height));
+ document.addPage(page);
+ contentStream = new PDPageContentStream(document, page);
+ pdfBoxGraphics2D = new PdfBoxGraphics2D(document, (float)width, (float)height);
+ return pdfBoxGraphics2D;
+ }
+
+ @Override
+ public void writeSlide(MFProxy proxy, File outFile) throws IOException {
+ pdfBoxGraphics2D.dispose();
+
+ PDFormXObject appearanceStream = pdfBoxGraphics2D.getXFormObject();
+ contentStream.drawForm(appearanceStream);
+ contentStream.close();
+ }
+
+ @Override
+ public void writeDocument(MFProxy proxy, File outFile) throws IOException {
+ document.save(new File(outFile.getCanonicalPath()));
+ }
+
+ @Override
+ public void close() throws IOException {
+ document.close();
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PDFFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1883074&r1=1883073&r2=1883074&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Mon Nov 2 23:56:27 2020
@@ -39,8 +39,6 @@ import org.apache.poi.sl.draw.EmbeddedEx
import org.apache.poi.util.Dimension2DDouble;
import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.xslf.util.OutputFormat.BitmapFormat;
-import org.apache.poi.xslf.util.OutputFormat.SVGFormat;
/**
* An utility to convert slides of a .pptx slide show to a PNG image
@@ -62,7 +60,7 @@ public final class PPTX2PNG {
" -scale <float> scale factor\n" +
" -fixSide <side> specify side (long,short,width,height) to fix - use <scale> as amount of pixels\n" +
" -slide <integer> 1-based index of a slide to render\n" +
- " -format <type> png,gif,jpg,svg (,null for testing)\n" +
+ " -format <type> png,gif,jpg,svg,pdf (,null for testing)\n" +
" -outdir <dir> output directory, defaults to origin of the ppt/pptx file\n" +
" -outfile <file> output filename, defaults to '"+OUTPUT_PAT_REGEX+"'\n" +
" -outpat <pattern> output filename pattern, defaults to '"+OUTPUT_PAT_REGEX+"'\n" +
@@ -207,7 +205,7 @@ public final class PPTX2PNG {
return false;
}
- if (format == null || !format.matches("^(png|gif|jpg|null|svg)$")) {
+ if (format == null || !format.matches("^(png|gif|jpg|null|svg|pdf)$")) {
usage("Invalid format given");
return false;
}
@@ -262,19 +260,19 @@ public final class PPTX2PNG {
final int width = Math.max((int)Math.rint(dim.getWidth()),1);
final int height = Math.max((int)Math.rint(dim.getHeight()),1);
- for (int slideNo : slidenum) {
- proxy.setSlideNo(slideNo);
- if (!quiet) {
- String title = proxy.getTitle();
- System.out.println("Rendering slide " + slideNo + (title == null ? "" : ": " + title.trim()));
- }
+ try (OutputFormat outputFormat = getOutput()) {
+ for (int slideNo : slidenum) {
+ proxy.setSlideNo(slideNo);
+ if (!quiet) {
+ String title = proxy.getTitle();
+ System.out.println("Rendering slide " + slideNo + (title == null ? "" : ": " + title.trim()));
+ }
- dumpRecords(proxy);
+ dumpRecords(proxy);
- extractEmbedded(proxy, slideNo);
+ extractEmbedded(proxy, slideNo);
- try (OutputFormat outputFormat = ("svg".equals(format)) ? new SVGFormat(textAsShapes) : new BitmapFormat(format)) {
- Graphics2D graphics = outputFormat.getGraphics2D(width, height);
+ Graphics2D graphics = outputFormat.addSlide(width, height);
// default rendering options
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@@ -294,9 +292,12 @@ public final class PPTX2PNG {
// draw stuff
proxy.draw(graphics);
- outputFormat.writeOut(proxy, new File(outdir, calcOutFile(proxy, slideNo)));
+ outputFormat.writeSlide(proxy, new File(outdir, calcOutFile(proxy, slideNo)));
}
+
+ outputFormat.writeDocument(proxy, new File(outdir, calcOutFile(proxy, 0)));
}
+
} catch (NoScratchpadException e) {
usage("'"+file.getName()+"': Format not supported - try to include poi-scratchpad.jar into the CLASSPATH.");
return;
@@ -307,6 +308,17 @@ public final class PPTX2PNG {
}
}
+ private OutputFormat getOutput() {
+ switch (format) {
+ case "svg":
+ return new SVGFormat(textAsShapes);
+ case "pdf":
+ return new PDFFormat();
+ default:
+ return new BitmapFormat(format);
+ }
+ }
+
private double getDimensions(MFProxy proxy, Dimension2D dim) {
final Dimension2D pgsize = proxy.getSize();
@@ -413,7 +425,7 @@ public final class PPTX2PNG {
return outfile;
}
String inname = String.format(Locale.ROOT, "%04d|%s|%s", slideNo, format, file.getName());
- String outpat = (proxy.getSlideCount() > 1 ? outPattern : outPattern.replaceAll("-?\\$\\{slideno}", ""));
+ String outpat = (proxy.getSlideCount() > 1 && slideNo > 0 ? outPattern : outPattern.replaceAll("-?\\$\\{slideno}", ""));
return INPUT_PATTERN.matcher(inname).replaceAll(outpat);
}
Added: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java?rev=1883074&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java Mon Nov 2 23:56:27 2020
@@ -0,0 +1,65 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+
+package org.apache.poi.xslf.util;
+
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.batik.dom.GenericDOMImplementation;
+import org.apache.batik.svggen.SVGGraphics2D;
+import org.apache.poi.util.Internal;
+import org.apache.poi.xslf.draw.SVGPOIGraphics2D;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+
+@Internal
+public class SVGFormat implements OutputFormat {
+ static final String svgNS = "http://www.w3.org/2000/svg";
+ private SVGGraphics2D svgGenerator;
+ private final boolean textAsShapes;
+
+ public SVGFormat(boolean textAsShapes) {
+ this.textAsShapes = textAsShapes;
+ }
+
+ @Override
+ public Graphics2D addSlide(double width, double height) {
+ // Get a DOMImplementation.
+ DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
+
+ // Create an instance of org.w3c.dom.Document.
+ Document document = domImpl.createDocument(svgNS, "svg", null);
+ svgGenerator = new SVGPOIGraphics2D(document, textAsShapes);
+ svgGenerator.setSVGCanvasSize(new Dimension((int)width, (int)height));
+ return svgGenerator;
+ }
+
+ @Override
+ public void writeSlide(MFProxy proxy, File outFile) throws IOException {
+ svgGenerator.stream(outFile.getCanonicalPath(), true);
+ }
+
+ @Override
+ public void close() throws IOException {
+ svgGenerator.dispose();
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/SVGFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org