Author: kiwiwings Date: Sun Dec 1 23:08:41 2019 New Revision: 1870694 URL: http://svn.apache.org/viewvc?rev=1870694&view=rev Log: Add slideshow, WMF, EMF, EMF+ rendering info
Added: poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml Modified: poi/site/src/documentation/content/xdocs/changes.xml poi/site/src/documentation/content/xdocs/site.xml Modified: poi/site/src/documentation/content/xdocs/changes.xml URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1870694&r1=1870693&r2=1870694&view=diff ============================================================================== --- poi/site/src/documentation/content/xdocs/changes.xml (original) +++ poi/site/src/documentation/content/xdocs/changes.xml Sun Dec 1 23:08:41 2019 @@ -88,7 +88,7 @@ <release version="4.1.2" date="2020-01-??"> <actions> - <action dev="PD" fixes-bug="63918" context="SL_Common XSLF">Fix texture fill - scale stretched images correctly</action> + <action dev="PD" type="fix" fixes-bug="63918" context="SL_Common XSLF">Fix texture fill - scale stretched images correctly</action> <action dev="PD" type="add" context="XSLF">Add, insert and remove columns on XSLFTable</action> <action dev="PD" type="fix" fixes-bug="63889" context="XDDF">Produce valid PPTX file with several chart series</action> <action dev="PD" type="add" context="XDDF">Add Doughnut chart data series support</action> Added: 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=1870694&view=auto ============================================================================== --- poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml (added) +++ poi/site/src/documentation/content/xdocs/components/slideshow/ppt-wmf-emf-renderer.xml Sun Dec 1 23:08:41 2019 @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- + ==================================================================== + 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. + ==================================================================== +--> +<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "document-v20.dtd"> + +<document> + <header> + <title>Rendering slideshows, WMF, EMF and EMF+</title> + </header> + <body> + <section> + <title>Rendering slideshows, WMF, EMF and EMF+</title> + <p> + For rendering slideshow (HSLF/XSLF), WMF, EMF and EMF+ pictures, POI provides an utility class + <a href="https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?view=markup"> + PPTX2PNG</a>: + </p> + + <source><![CDATA[ + Usage: PPTX2PNG [options] <ppt or pptx file or 'stdin' + + Options: + -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 (,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}" + patterns: basename, slideno, format, ext + -dump <file> dump the annotated records to a file + -quiet do not write to console (for normal processing) + -ignoreParse ignore parsing error and continue with the records read until the error + -extractEmbedded extract embedded parts + ]]> + </source> + </section> + <section> + <title>Integrate rendering in your code</title> + <section> + <title>#1 - Use PPTX2PNG via file or stdin</title> + <p>For file system access, you need to save your slideshow/WMF/EMF/EMF+ first to disc and then call <code> + PPTX2PNG.main() + </code> with the corresponding parameters. + </p> + + <p>for stdin access, you need to redirect <code>System.in</code> before: + </p> + <source><![CDATA[ + /* the file content */ + InputStream is = ...; + /* Save and set System.in */ + InputStream oldIn = System.in; + try { + System.setIn(is); + + String[] args = { + "-format", "png", // png,gif,jpg or null for test + "-outdir", new File("out/").getCanonicalPath(), + "-outfile", "export.png", + "-fixside", "long", + "-scale", "800", + "-ignoreParse", + "stdin" + }; + PPTX2PNG.main(args); + + } finally { + System.setIn(oldIn); + } + ]]></source> + </section> + <section> + <title>#2 - Render WMF / EMF / EMF+ via the *Picture classes</title> + <source><![CDATA[ + File f = samples.getFile("santa.wmf"); + try (FileInputStream fis = new FileInputStream(f)) { + // for WMF + HwmfPicture wmf = new HwmfPicture(fis); + + // for EMF / EMF+ + HemfPicture emf = new HemfPicture(fis); + + Dimension dim = wmf.getSize(); + int width = Units.pointsToPixel(dim.getWidth()); + // keep aspect ratio for height + int height = Units.pointsToPixel(dim.getHeight()); + double max = Math.max(width, height); + if (max > 1500) { + width *= 1500/max; + height *= 1500/max; + } + + BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = bufImg.createGraphics(); + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + + wmf.draw(g, new Rectangle2D.Double(0,0,width,height)); + + g.dispose(); + + ImageIO.write(bufImg, "PNG", new File("bla.png")); + } + ]]> + </source> + </section> + <section> + <title>#3 - Render slideshows directly</title> + <source><![CDATA[ + File file = new File("example.pptx"); + double scale = 1.5; + try (SlideShow<?, ?> ss = SlideShowFactory.create(file, null, true)) { + Dimension pgsize = ss.getPageSize(); + int width = (int) (pgsize.width * scale); + int height = (int) (pgsize.height * scale); + + for (Slide<?, ?> slide : ss.getSlides()) { + BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics = img.createGraphics(); + + // default rendering options + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + graphics.setRenderingHint(Drawable.BUFFERED_IMAGE, new WeakReference<>(img)); + + graphics.scale(scale, scale); + + // draw stuff + slide.draw(graphics); + + ImageIO.write(img, "PNG", new File("output.png")); + graphics.dispose(); + img.flush(); + } + } + ]]></source> + </section> + </section> + </body> +</document> \ No newline at end of file Modified: poi/site/src/documentation/content/xdocs/site.xml URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/site.xml?rev=1870694&r1=1870693&r2=1870694&view=diff ============================================================================== --- poi/site/src/documentation/content/xdocs/site.xml (original) +++ poi/site/src/documentation/content/xdocs/site.xml Sun Dec 1 23:08:41 2019 @@ -75,6 +75,7 @@ See http://xml.apache.org/forrest/linkin <slquickguide label="Quick Guide" href="quick-guide.html"/> <hslfcook label="HSLF Cookbook" href="how-to-shapes.html"/> <xslfcook label="XSLF Cookbook" href="xslf-cookbook.html"/> + <slrender label="Render SL/WMF/EMF" href="ppt-wmf-emf-renderer.html"/> <format label="PPT File Format" href="ppt-file-format.html"/> </slideshow> <document label="Word (HWPF/XWPF)" href="document/"> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org For additional commands, e-mail: commits-h...@poi.apache.org