|
// For complete examples and data files, please go to https://github.com/aspose-cad-cloud/aspose-cad-cloud-dotnet/ |
|
|
|
using Aspose.CAD.Cloud.Sdk; |
|
using Aspose.CAD.Cloud.Sdk.Client; |
|
using Aspose.CAD.Cloud.Sdk.Model.Requests; |
|
using Aspose.Storage.Cloud.Sdk.Api; |
|
using Aspose.Storage.Cloud.Sdk.Model.Requests; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
|
|
namespace Aspose.CAD_Cloud_APIs_Examples |
|
{ |
|
class CADExamples |
|
{ |
|
protected string AppKey = ""; // Get App Key and App SID from https://dashboard.aspose.cloud/ |
|
protected string AppSid = ""; // Get App Key and App SID from https://dashboard.aspose.cloud/ |
|
|
|
static void Main(string[] args) |
|
{ |
|
CADExamples cadExamples = new CADExamples(); |
|
|
|
// Export existing drawing to another format |
|
cadExamples.GetImageSaveAs(); |
|
} |
|
|
|
// Export existing drawing to another format |
|
private void GetImageSaveAs() |
|
{ |
|
CADApi cadApi = new CADApi(AppKey, AppSid); |
|
string fileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.dwg"; |
|
// Possible values are jpg, bmp, psd, tiff, gif, png, j2k, wmf and pdf |
|
string formatToExport = "pdf"; |
|
string destFileName = "01.026.385.01.0.I SOPORTE ENFRIADOR.pdf"; |
|
|
|
// Upload document to Cloud Storage |
|
uploadFileToCloudStorage(fileName); |
|
|
|
var request = new GetImageSaveAsRequest(fileName, formatToExport, null, null, null, null); |
|
var responseStream = cadApi.GetImageSaveAs(request); |
|
|
|
// Save the output file to disk |
|
saveFileToDisk(responseStream, destFileName); |
|
} |
|
|
|
private string pathToDataDir() |
|
{ |
|
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; |
|
var folders = Path.GetDirectoryName(baseDirectory).Split('\\').ToList(); |
|
// Get Path to the TestData directory |
|
var foldersUpToRootDir = folders.Take(folders.Count - 5); |
|
var pathToRootDir = string.Join("\\", foldersUpToRootDir); |
|
return Path.Combine(pathToRootDir, "TestData"); |
|
} |
|
|
|
private void uploadFileToCloudStorage(String fileName) |
|
{ |
|
StorageApi storageApi = new StorageApi(AppKey, AppSid); |
|
|
|
string dataFilePath = Path.Combine(pathToDataDir(), fileName); |
|
|
|
PutCreateRequest putCreateRequest = new PutCreateRequest(fileName, File.OpenRead(dataFilePath), null, null); |
|
storageApi.PutCreate(putCreateRequest); |
|
} |
|
|
|
private void saveFileToDisk(Stream responseStream, String destFileName) |
|
{ |
|
var fileStream = File.Create(Path.Combine(pathToDataDir(), "Output", destFileName)); |
|
responseStream.Seek(0, SeekOrigin.Begin); |
|
responseStream.CopyTo(fileStream); |
|
fileStream.Close(); |
|
} |
|
} |
|
} |