Bug 63290 - PPTX To Png changes font sizes and colors
Summary: PPTX To Png changes font sizes and colors
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 4.0.x-dev
Hardware: Macintosh Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-27 11:46 UTC by tyler_cronin
Modified: 2020-07-06 07:19 UTC (History)
0 users



Attachments
This is the power point that we use and the results from running them through poi. (119.59 KB, application/zip)
2019-03-27 11:46 UTC, tyler_cronin
Details
PowerPoint presentation containing one text field containing one paragraph having the issue. (31.13 KB, application/vnd.openxmlformats-officedocument.presentationml.presentation)
2020-05-20 15:18 UTC, Axel Richter
Details
PPT file used for conversion (399.71 KB, application/vnd.openxmlformats-officedocument.presentationml.presentation)
2020-05-21 04:10 UTC, jitendra
Details
generated image (74.43 KB, image/jpeg)
2020-05-21 04:11 UTC, jitendra
Details
PPTx To image through Spire java libraries (173.02 KB, image/png)
2020-05-28 02:52 UTC, jitendra
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tyler_cronin 2019-03-27 11:46:44 UTC
Created attachment 36499 [details]
This is the power point that we use and the results from running them through poi.

When we run a power point through the xslf it changes the font sizes and colors. This results in the text boxes being misaligned or moved. We appreciate any help with this.
Comment 1 Axel Richter 2020-05-20 15:18:53 UTC
Created attachment 37259 [details]
PowerPoint presentation containing one text field containing one paragraph having the issue.
Comment 2 Axel Richter 2020-05-20 15:19:52 UTC
Used PowerPoint presentation, see attachment.
This only contains one text field containing one paragraph having the issue.
Used Code:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import java.util.List;
 
public class PptToImageSimplest {
 public static void main(String args[]) throws Exception {
  FileInputStream in =new FileInputStream("PPT.pptx");
  XMLSlideShow ppt = new XMLSlideShow(in);
  //get the dimension of size of the slide
  Dimension pgsize = ppt.getPageSize();
  //get slides
  List<XSLFSlide> slides = ppt.getSlides();
  BufferedImage img = null;
  FileOutputStream out = null;
  for (int i = 0; i < slides.size(); i++) {
   img = new BufferedImage((int)Math.ceil(pgsize.width), (int)Math.ceil(pgsize.height), BufferedImage.TYPE_INT_RGB);
   Graphics2D graphics = img.createGraphics();
   //clear the drawing area
   graphics.setPaint(Color.white);
   graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
   //render
   slides.get(i).draw(graphics);
   //creating an image file as output
   out = new FileOutputStream("ppt_image_" + i + ".png");
   ImageIO.write(img, "png", out);
   out.close();    
  }
 }
}
 

Problem:
Apache POI .draw(graphics) does not draw the first text run in text field properly.
Reason:
The text field contains a paragraph which uses Default Run Properties in  Paragraph Properties. The first text run has no Run Properties of it's own. XML looks like:

<a:p>
 <a:pPr>
  <a:defRPr lang="de-DE" sz="4000" dirty="0" err="1" smtClean="0">
   <a:solidFill>
    <a:srgbClr val="FF0000"/>
   </a:solidFill>
  </a:defRPr>
 </a:pPr>
 <a:r>
  <a:t>DefaultRunProperties </a:t>
 </a:r>
 <a:r>
  <a:rPr lang="de-DE" sz="4000" dirty="0" err="1" smtClean="0">
   <a:solidFill>
    <a:srgbClr val="00FF00"/>
   </a:solidFill>
  </a:rPr>
  <a:t>ExplicitRunProperties</a:t>
 </a:r>
</a:p>

PowerPoint renders it so that first run inherits the defRP. But Apache POI does not.
Comment 3 jitendra 2020-05-21 04:10:40 UTC
Created attachment 37262 [details]
PPT file used for conversion
Comment 4 jitendra 2020-05-21 04:11:21 UTC
Created attachment 37263 [details]
generated image
Comment 5 jitendra 2020-05-28 02:52:30 UTC
Created attachment 37271 [details]
PPTx To image through Spire java libraries

the same PPTx converted through Spire java libraries is producing the correct output.
Comment 6 Andreas Beeker 2020-06-04 23:19:31 UTC
applied via r1878492
various fixes to HSLF
moved line spacing to the following line
refactored PropertyFetcher with lambdas
Comment 7 jitendra 2020-07-02 04:06:01 UTC
Regarding r1878492, Is there any maven release for this bug fix ?
Comment 8 Andreas Beeker 2020-07-02 10:56:05 UTC
(In reply to jitendra from comment #7)
> Regarding r1878492, Is there any maven release for this bug fix ?

No ... the next official release (5.0.0) won't be available for the next few weeks, as we work on providing a modular (jigsaw) version. Either you download a nightly and install it (http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html) or you download the source and call "ant mvn-install"
Comment 9 jitendra 2020-07-06 07:19:58 UTC
I tried the 5.0 jars and it resolved the problem(text overlapping) i have reported.