자바에서 변수에 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
- 1. html 파일에서 렌더링되는 aspose ppt에 스타일을 포함 할 수 없습니다. aspose Java 라이브러리를 사용하여 html을 ppt로 변환하고 있습니다.
- 2. HTML을 PPT로 변환. 닷넷 라이브러리
- 3. 온라인으로 sharepoint에 Aspose 라이브러리를 추가하는 방법은 무엇입니까?
- 4. Aspose
- 5. 윈도우 위치가 ppt로 대체됩니다.
- 6. UNIX에서 PPT로 변환하는 변환기
- 7. VBA 엑셀에서 PPT로 내보내기
- 8. 방향성 그래프를 자바 라이브러리를 사용하여 방향이없는 방향으로 변환
- 9. 덜 순수한 CSS 또는 덜 자바 스크립트 라이브러리를 사용하여 변환
- 10. Aspose 수식
- 11. MVC3 LoadData의 Aspose 오류
- 12. Aspose 셀 자바, 테이블/ListObject에서 이미지를 만드는 방법
- 13. 자바 메소드는 자바 라이브러리를 사용하여 ColdFusion에서
- 14. Aspose Formatting
- 15. python2 라이브러리를 python3으로 변환
- 16. xml 파일을 .doc 또는 .ppt로 변환하십시오.
- 17. 버크 라이브러리를 사용하여 십진수로 변환 R
- 18. spire 라이브러리를 사용하여 Excel로 PDF 변환
- 19. ImageMagic 라이브러리를 사용하여 이미지를 픽스맵으로 변환
- 20. 변환 PDF는 현명한 pdfbox 라이브러리를 사용하여
- 21. jspdf 라이브러리를 사용하여 html 파일을 pdf로 변환
- 22. Aspose lib를 자바로 사용하여 Office 파일을 PDF로 변환하는 방법
- 23. Aspose 테이블 삽입
- 24. 단어를 aspose 단어를 사용하여 2 줄로 나누었습니다.
- 25. Aspose pdf417 recognition
- 26. Aspose PPT/Slides에서 페이지 설정
- 27. 자바 라이브러리를 찾고 만화 그림을
- 28. Aspose tiff 변환 된 PDF가 Adobe에서 열리지 않습니다. Foxit
- 29. 자바 스크립트를 사용하여 최대 라텍스로 변환
- 30. 자바 용 aspose 셀의 행에 필터를 적용하는 방법
어떤 것을 시도해 보셨습니까? –
어디서나 작동 코드를 찾을 수 없습니다. –