Leonel FOFOU
2026-07-28 32450e295200b2bc7896518ff74161ff26772e2d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.megatim.manuel.core.convert;
 
import org.apache.poi.hslf.usermodel.HSLFSlide;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
 
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
 
/**
 * PowerPoint .ppt hérité (HSLF) -> HTML : chaque diapositive est rendue en image PNG,
 * et son titre devient une entrée de la table des matières.
 */
public class PptConverter extends AbstractHtmlConverter {
 
    private static final double SCALE = 2.0;
 
    public PptConverter(Path outputDir) {
        super(outputDir);
    }
 
    @Override
    public ConversionResult convert(Path source, int order) throws IOException {
        String safe = safeBase(source, order);
        String htmlName = safe + ".html";
        List<Heading> headings = new ArrayList<>();
        List<String> images = new ArrayList<>();
        StringBuilder body = new StringBuilder();
 
        try (FileInputStream fis = new FileInputStream(source.toFile());
             HSLFSlideShow ppt = new HSLFSlideShow(fis)) {
 
            Dimension d = ppt.getPageSize();
            int w = (int) Math.round(d.width * SCALE);
            int h = (int) Math.round(d.height * SCALE);
 
            int n = 0;
            for (HSLFSlide slide : ppt.getSlides()) {
                n++;
                String title = slide.getTitle();
                if (title == null || title.isBlank()) title = "Diapositive " + n;
 
                BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
                Graphics2D g = img.createGraphics();
                applyQualityHints(g);
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, w, h);
                g.scale(SCALE, SCALE);
                try {
                    slide.draw(g);
                } finally {
                    g.dispose();
                }
 
                String imgName = writeImagePng(safe, n, img);
                images.add(imgName);
 
                String anchor = safe + "_s" + n;
                headings.add(new Heading(title, 1, anchor));
                body.append("<h1 id=\"").append(anchor).append("\">").append(esc(title)).append("</h1>\n");
                body.append("<p class=\"slide\"><img src=\"").append(imgName)
                    .append("\" alt=\"").append(esc(title)).append("\"/></p>\n");
            }
        }
 
        String docTitle = headings.isEmpty() ? stripExt(source.getFileName().toString()) : headings.get(0).text;
        writeHtml(htmlName, docTitle, body.toString());
        return new ConversionResult(htmlName, docTitle, headings, images);
    }
}