Substitua a imagem no PowerPoint pela API REST C#

Este artigo orienta como substituir a imagem em PowerPoint pela API REST C#. Você aprenderá como substituir imagem no PowerPoint pela interface REST C# usando o Cloud SDK baseado em .NET. Ele fornecerá detalhes completos para fazer upload dos arquivos de origem e baixar os arquivos modificados do armazenamento em nuvem.

Pré-requisito

Etapas para substituir imagem em PPT por API baseada em C# .NET

  1. Inicialize o objeto da classe SlidesApi para substituir a imagem
  2. Carregue a apresentação de destino com algumas imagens para substituição
  3. Carregue a imagem de origem em um objeto Stream para adicioná-la à apresentação
  4. Invoque o método ReplaceImage() fornecendo o nome da apresentação, o índice da imagem de destino e o novo fluxo de imagem
  5. Baixe a apresentação modificada com uma nova imagem

As etapas descrevem como substituir a imagem no PowerPoint pela interface REST C#. Carregue a apresentação de origem para o armazenamento em nuvem, leia a imagem desejada no objeto Stream e chame o método ReplaceImage() com os argumentos necessários. Posteriormente, chame o método DownloadFile para buscar a apresentação atualizada.

Código para substituir imagem em PPT com API REST C#

using Aspose.Slides.Cloud.Sdk;
using System;
using System.IO;
namespace SlideEditor
{
class UpdatePresentation
{
static void Main(string[] args)
{
// Set up the API client with access credentials
var slidesApiClient = new SlidesApi("Client ID", "Secret");
// Specify the name of the presentation file
string inputPresentation = "InputSlides.pptx";
// Upload the presentation to the server for processing
var uploadResult = slidesApiClient.UploadFile(inputPresentation, new MemoryStream(File.ReadAllBytes(inputPresentation)));
// Open the image file to replace an image in the presentation
Stream replacementImage = File.OpenRead("ReplacementImage.png");
// Replace the image on the first slide
slidesApiClient.ReplaceImage("InputSlides.pptx", 1, replacementImage);
Console.WriteLine("Image on index 1 has been replaced successfully.");
// Download the updated presentation back from the server
Stream modifiedPresentationStream = slidesApiClient.DownloadFile(inputPresentation);
// Save the updated presentation locally with a new name
using (var saveFileStream = new FileStream("UpdatedSlides.pptx", FileMode.Create, FileAccess.Write))
{
modifiedPresentationStream.CopyTo(saveFileStream);
}
Console.WriteLine("Updated presentation saved as 'UpdatedSlides.pptx'.");
}
}
}

Este código demonstrou como alterar o formato da imagem no PowerPoint com C# RESTful Service. Se você não carregar o arquivo de apresentação para o armazenamento em nuvem, ele usará qualquer apresentação disponível com o mesmo nome no armazenamento em nuvem. Você poderá obter resultados diferentes se usar o nome de arquivo existente do armazenamento em nuvem carregado anteriormente em alguma outra sessão.

Este artigo nos ensinou o processo de substituição de uma imagem em uma apresentação. Para adicionar uma nova imagem, consulte o artigo em Adicionar imagem ao PowerPoint com API REST C#.

 Português