Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java aspose库将html转换为ppt_Java_Html_Powerpoint_Aspose - Fatal编程技术网

使用java aspose库将html转换为ppt

使用java aspose库将html转换为ppt,java,html,powerpoint,aspose,Java,Html,Powerpoint,Aspose,我正在用java将html代码传递给一个变量。使用aspose库,应该执行html代码并将其呈现到ppt中(我还在html中引用css)。 如果ppt是可编辑的,我将不胜感激。我已注意到您的要求,很抱歉与您分享。幻灯片是用于管理PowerPoint幻灯片的API,不支持将HTML转换为ppt/PPTX的功能。但是,它支持在幻灯片文本框中导入HTML文本,您可以使用这些文本框 // Create Empty presentation instance// Create Empty presenta

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

我已注意到您的要求,很抱歉与您分享。幻灯片是用于管理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担任技术支持开发人员/宣传员。

我注意到了您的要求,很抱歉与您分享Aspose。幻灯片是用于管理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担任支持开发人员/布道者。

请使用以下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等效代码

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();

}
@巴尔昌达·雷迪

我注意到了您的评论,希望与大家分享导入HtmlTextInParagraphs.class指向文件路径的内容。我已经更新了与此相关的代码

其次,您需要在自己的位置调用import com.aspose.slides.IAutoShape来解决问题。

@Balchandar Reddy

我注意到了您的评论,希望与大家分享导入HtmlTextInParagraphs.class指向文件路径的内容。我已经更新了与此相关的代码


其次,您需要调用import com.aspose.slides.IAutoShape来解决此问题。

您尝试过任何东西吗?在任何地方都找不到aspose的工作代码吗?在任何地方都找不到aspose的工作代码请使用以下java等效代码。@Balchandar Reddy,我注意到了您的评论,并希望与大家分享ImportingHTMLTextInParagraphs.class指向文件路径的内容。我已经更新了与此相关的代码。其次,您需要调用import com.aspose.slides.IAutoShape来解决此问题。请使用以下与java等效的代码。@Balchandar Reddy,我注意到了您的评论,并希望与大家分享ImportingHTMLTextInParagraphs.class指向文件路径的内容。我已经更新了与此相关的代码。其次,您需要调用import com.aspose.slides.IAutoShape来解决问题。我已经尝试过了。但是,iautose库无法解决IAutoShape问题。类ImportingHTMLTextInParagraphs.class加载有什么问题?我已经尝试过了。但是,IAutoShape未通过aspose库解决。类导入HtmlTextInParagraphs.class加载有什么问题?我无法完全按照预期呈现html。它正在呈现,但无法加载大多数样式。(例如,它可以加载样式颜色:红色;但不能加载样式背景颜色:红色;),有什么建议吗?我已经在您发起的单独线程中分享了对您上述请求的响应。我无法完全按照预期呈现html。它正在呈现,但无法加载大多数样式。(例如,它可以加载样式颜色:红色;但不能加载样式背景颜色:红色;),有什么建议吗?我已经在您发起的单独线程中分享了对您上述请求的响应。