Created
August 6, 2024 11:07
Convert SVG to WMF with NET REST API. https://kb.aspose.cloud/imaging/net/convert-svg-to-wmf-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging.Cloud.Sdk.Api; | |
using Aspose.Imaging.Cloud.Sdk.Model.Requests; | |
using Aspose.Imaging.Cloud.Sdk.Model; | |
using System; | |
using System.IO; | |
namespace Kb_Aspose.KB | |
{ | |
public class SvgToWmfConverter | |
{ | |
public void SvgToWmf() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var svgToWmfImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Source.svg"; | |
var outputFileName = "SvgtoWmf.wmf"; | |
var outputFormat = "wmf"; | |
var remoteFolder = null; // source file is saved at the root of the storage | |
var remoteStorage = null; // remote cloud Storage place name | |
try | |
{ | |
// Upload the source SVG file to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadSvgFileReq = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
svgToWmfImageApi.UploadFile(uploadSvgFileReq); | |
var convertSvgToWmfRequest = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var wmfDataStream = svgToWmfImageApi.ConvertImage(convertSvgToWmfRequest); | |
wmfDataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
wmfDataStreamDataStream.Seek(0, SeekOrigin.Begin); | |
wmfDataStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment