我正在將html代碼傳遞給java中的變量。使用aspose庫,應該執行html代碼並將其渲染爲ppt(我也在html中引用了對css的引用)。如果ppt是可編輯的,則可以使用 。使用java aspose庫將html轉換爲ppt
回答
我已經觀察到您的要求並遺憾地分享Aspose.Slides是用於管理PowerPoint幻燈片的API,但不支持將HTML轉換爲PPT/PPTX的功能。但是,它支持導入可能使用的幻燈片文本框架內的HTML文本。
// Create Empty presentation instance// Create Empty presentation instance
using (Presentation pres = new Presentation())
{
// Acesss the default first slide of presentation
ISlide slide = pres.Slides[0];
// Adding the AutoShape to accomodate the HTML content
IAutoShape ashape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, pres.SlideSize.Size.Width - 20, pres.SlideSize.Size.Height - 10);
ashape.FillFormat.FillType = FillType.NoFill;
// Adding text frame to the shape
ashape.AddTextFrame("");
// Clearing all paragraphs in added text frame
ashape.TextFrame.Paragraphs.Clear();
// Loading the HTML file using stream reader
TextReader tr = new StreamReader(dataDir + "file.html");
// Adding text from HTML stream reader in text frame
ashape.TextFrame.Paragraphs.AddFromHtml(tr.ReadToEnd());
// Saving Presentation
pres.Save("output_out.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
我在Aspose擔任Support developer/Evangelist。
請在結尾處使用以下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();
}
我試過了,但IAutoShape沒有通過aspose庫解決。 –
和什麼abt的類ImportingHTMLTextInParagraphs.class加載? –
@Balchandar雷迪,
我觀察到您的意見和喜歡分享ImportingHTMLTextInParagraphs.class指向文件的路徑。我已經更新了與此相關的代碼。其次,您需要致電導入com.aspose.slides.IAutoShape以解決問題。
明白了..謝謝你..! –
我不能完全呈現HTML的意圖..它呈現,但無法加載大部分的樣式。 (例如,它可以加載樣式顏色:紅色;但不是樣式背景顏色:紅色;),有什麼建議? –
我在您發起的獨立線索中分享了您對上述請求的回覆。 https://stackoverflow.com/questions/46358541/unable-to-embed-styling-in-aspose-ppt-which-is-rendered-from-html-file/46361091#46361091 – Mudassir
- 1. HTML到PPT轉換.Net庫
- 2. 使用Aspose進行HTML到PDF轉換
- 3. 我可以使用okapi和java將doc轉換爲docx,ppt轉換爲pptx,xls轉換爲xlsx,反之亦然?
- 4. 使用Java標準庫將HTML字符轉換爲文本
- 5. 使用aspose api更改java中幻燈片的文本ppt
- 6. 將pdf,doc,ppt轉換爲html5
- 7. 將ppt或pptx文件轉換爲jpg
- 8. 通過python將PPT轉換爲PNG
- 9. C#轉換爲.ppt圖像
- 10. 在PPT中將PPTX或PPT文件轉換爲PDF格式
- 11. Aspose cell exception:om.ctc.wstx.sr.ValidatingStreamReader無法轉換爲com.ctc.wstx.sr.ValidatingStreamReader
- 12. 如何使用Rmagick將ppt轉換爲pdf?
- 13. 使用XSD/trang HTML 5驗證Java HTML 5將NG轉換爲XSD轉換
- 14. Applescript - 批量轉換PPT到HTML
- 15. 任何用於ppt到jpg轉換的java庫?
- 16. 用於將xml/html轉換爲pdf的java庫
- 17. 轉換HTML文件爲PDF使用Java
- 18. 將Markdown轉換爲HTML的ActionScript庫
- 19. 將PDF轉換爲PHP中的HTML庫
- 20. 將HTML符號轉換爲Java符號
- 21. 在Java中將HTML轉換爲RTF?
- 22. 將HTML表格轉換爲Java
- 23. 將html轉換爲java中的doc
- 24. 轉換PPT到JPG
- 25. 使用jQuery將JSON轉換爲HTML jPut
- 26. 使用PDFSharp將HTML轉換爲PDF
- 27. 使用jQuery將jQuery.parseXML值轉換爲HTML
- 28. 使用javascript將HTML轉換爲圖像
- 29. 使用Python將.doc轉換爲.html
- 30. 使用javascript/jquery將html轉換爲svg
你有試過任何東西嗎? –
無法找到aspose的任何工作代碼 –