问题描述
我使用aspose java库将html转换为ppt。但是,我无法生成类似(填充,背景颜色等)的样式,而像(颜色,字体大小)等样式工作得很好,请查看代码..
public class poi {
public static void main(String [] args)throws Exception {
//文档目录的路径。
String dataDir = Utils.getDataDir(poi.class);
//创建空演示文稿实例
演示文稿pres =新演示文稿();
//访问演示文稿的默认第一张幻灯片
ISlide slide = pres.getSlides()。get_Item(0);
//添加自选图形以适应HTML内容
IAutoShape ashape = slide.getShapes()。addAutoShape(ShapeType.Rectangle,50,150,300,150);
ashape.getFillFormat()。setFillType(FillType.NoFill);
//将文本框添加到形状
ashape.addTextFrame();
//清除添加文本框中的所有段落
ashape.getTextFrame()。getParagraphs()。clear();
//使用InputStream加载HTML文件
InputStream inputStream = new FileInputStream(dataDir +file.html);
Reader reader = new InputStreamReader(inputStream);
int data = reader.read();
String content = ReadFile(dataDir +file.html);
//在文本框中添加来自HTML流式阅读器的文本
ashape.getTextFrame()。getParagraphs()。addFromHtml(content);
//保存表示
pres.save(dataDir +output.pptx,SaveFormat.Pptx);
$ b public static String ReadFile(String FileName)throws Exception {
File file = new File(FileName);
StringBuilder contents = new StringBuilder();
BufferedReader reader = null;
尝试{
reader = new BufferedReader(new FileReader(file));
String text = null; $($ 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();
返回null;
}
}
return contents.toString();
}
}
看到我正在加载具有内联样式的html文件,但我无法完成大部分要加载的CSS元素。任何建议?
@Balchandar Reddy,
您的要求,并希望目前Aspose.Slides支持基本文本导入以及使用Aspose.Slides生成的演示文稿中的有限标记支持。我请求您请分享所需的HTML,并使用您希望在Aspose.Slides中支持的所需标签。我将与我们的产品团队讨论这个问题,并将其添加为问题跟踪系统中的新功能请求。
我在Aspose担任Support developer / Evangelist。 p>
I am converting html to ppt using aspose java library. But, I couldn't generate styles like (padding,background-color,etc) whereas styles like(color,font-size) are working just fine,have a look at the code..
public class poi {
public static void main(String[] args) throws Exception {
// The path to the documents directory.
String dataDir = Utils.getDataDir(poi.class);
// 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, 50, 150, 300, 150);
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();
}
}
As you can see I am loading the html file which has inline styling, but I couldn't quite make most of the css elements to load. Any suggestions?
@Balchandar Reddy,
I have observed your requirements and like to share that at present Aspose.Slides support basic text import along with limited tag support in presentations generated using Aspose.Slides. I request you to please share the required HTML with desired tags for which you intend to have support in Aspose.Slides. I will discuss that with our product team and will add that as new feature request in our issue tracking system.
I am working as Support developer/ Evangelist at Aspose.
这篇关于无法将样式嵌入到从html文件呈现的aspose ppt中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!