gpt4 book ai didi

java - 使用java aspose库将html转换为ppt

转载 作者:行者123 更新时间:2023-12-02 02:36:36 25 4
gpt4 key购买 nike

我正在将 html 代码传递给 java 中的变量。使用aspose库,应该执行html代码并将其呈现为ppt(我还在html中给出了对css的引用)。如果 ppt 可以编辑,我们将不胜感激。

最佳答案

请在您端使用以下 Java 等效代码。

public static void main(String[] args) throws Exception {

// The path to the documents directory.
String dataDir ="C:\\html\\";

// Create Empty presentation instance
Presentation pres = new Presentation();

// Access the default first slide of presentation
ISlide slide = pres.getSlides().get_Item(0);

// Adding the AutoShape to accommodate the HTML content
IAutoShape ashape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, (float) pres.getSlideSize().getSize().getWidth(), (float) pres.getSlideSize().getSize().getHeight());

ashape.getFillFormat().setFillType(FillType.NoFill);

// Adding text frame to the shape
ashape.addTextFrame("");

// Clearing all paragraphs in added text frame
ashape.getTextFrame().getParagraphs().clear();

// Loading the HTML file using InputStream
InputStream inputStream = new FileInputStream(dataDir + "file.html");
Reader reader = new InputStreamReader(inputStream);

int data = reader.read();
String content = ReadFile(dataDir + "file.html");

// Adding text from HTML stream reader in text frame
ashape.getTextFrame().getParagraphs().addFromHtml(content);

// Saving Presentation
pres.save(dataDir + "output.pptx", SaveFormat.Pptx);

}

public static String ReadFile(String FileName) throws Exception {

File file = new File(FileName);
StringBuilder contents = new StringBuilder();
BufferedReader reader = null;

try {
reader = new BufferedReader(new FileReader(file));
String text = null;

// repeat until all lines is read
while ((text = reader.readLine()) != null) {
contents.append(text).append(System.getProperty("line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}

return contents.toString();

}

关于java - 使用java aspose库将html转换为ppt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46217033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com