Merge HTML to Image in PHP

Combine HTML content and render it as images with Aspose.Slides for PHP via Java.

Merge HTML to PNG in PHP

Using Aspose.Slides for PHP via Java , you can import two HTML files and render every resulting slide as a PNG image with a few lines of PHP code.

PHP code for merging HTML to PNG

$presentation = new Presentation();
try {
    $presentation->getSlides()->removeAt(0);

    $firstHtmlContent = file_get_contents("file1.html");
    $presentation->getSlides()->addFromHtml($firstHtmlContent);

    $secondHtmlContent = file_get_contents("file2.html");
    $presentation->getSlides()->addFromHtml($secondHtmlContent);

    $slideCount = java_values($presentation->getSlides()->size());
    for ($slideIndex = 0; $slideIndex < $slideCount; $slideIndex++) {
        $slide = $presentation->getSlides()->get_Item($slideIndex);
        $slideImage = $slide->getImage(1.0, 1.0);

        try {
            $filePath = "merged-slide-" . ($slideIndex + 1) . ".png";
            $slideImage->save($filePath, ImageFormat::Png);
        } finally {
            $slideImage->dispose();
        }
    }
} finally {
    $presentation->dispose();
}

Merge HTML to PNG using Aspose.Slides

Aspose.Slides for PHP via Java can import content from multiple HTML files into a Presentation and render the resulting slides as PNG images. Each generated slide is saved as a separate image so that all imported content is preserved.

How to merge HTML to image in PHP

  1. Install Aspose.Slides for PHP via Java. See Installation.
  2. Configure Aspose.Slides in your PHP project.
  3. Create a Presentation instance and remove its default slide.
  4. Read the HTML files with file_get_contents and import their content with addFromHtml.
  5. Render each slide with getImage and save it with ImageFormat::Png.

Built with Aspose.Slides

Merge HTML to Image Online

The free Aspose.Slides Merger app is built with Aspose.Slides for PHP via Java, the same API as the code above. Open it and see what the API can do with your own HTML files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides merges files before you write code.
  • Upload several HTML files and combine them into one Image file.
  • Download the merged result as one file.

Merge Other Files

You can also combine files in other supported formats.