자바에서 변수에 html 코드를 전달 중입니다. aspose 라이브러리를 사용하여 html 코드를 실행하고 ppt로 렌더링해야합니다 (html의 css에 대한 참조도 제공합니다). 은 ppt가 편집 가능한 경우에 높이 평가됩니다.자바 aspose 라이브러리를 사용하여 hpt를 ppt로 변환
답변
PowerPoint 슬라이드를 관리하기위한 API 인 Aspose.Slides가 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에서 지원 개발자/전도사로 일하고 있습니다.
끝 부분에 다음 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 라이브러리에 의해 해결되지 않았다. –
그리고 ImportingHTMLTextInParagraphs.class 클래스의 abt 클래스는 무엇입니까? –
@Balchandar 레디
나는 당신의 의견을 관찰 및 파일의 경로로 그 ImportingHTMLTextInParagraphs.class에게 점을 공유하고있다. 나는 이것과 관련된 코드를 업데이트했다.
둘째, 문제를 해결하려면 import 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
어떤 것을 시도해 보셨습니까? –
어디서나 작동 코드를 찾을 수 없습니다. –