Data processing is the backbone of any organization. It mostly gives insight about a company's progress or a way to keep track of the progress. There are almost five stages of data processing and Data conversion is one of the important stage.
Data/Document Conversion
A document basically possesses some data. It could be a PDF, Word, Spreadsheet, an Image file or a Drawing (e.g. AutoCAD file). For example, your business need is to take an AutoCAD file as input from a cloud storage (e.g. Amazon S3, Azure Blob) and convert it to PDF or a Presentation format. So that you can present/explain it to the concerned community without a need of installing AutoCAD.
At this point, you really need a documnet converter. Isn't it better to write your own document conversion application?
Introduction to the Document Conversion API
In this blog post, we'll see how we could pull a document from cloud storage, pass it to the document conversion API and generate an output (converted file). The API we'll use is GroupDocs.Conversion for .NET.
This back-end, UI-Agnostic API could be integrated in any .NET application irrespective of platform or framework dependecies. Have a look at the minimum requriements to get started with and this installation guide.
Processing or Implementation
Pull Source file from S3 Storage and Convert it to PDF
The minimal code to meet the requirement is given below,
- public static void Run()
- {
- string key = "sample.docx";
- string outputFile = Path.Combine("c:\output" , "converted.pdf");
- using (Converter converter = new Converter(() => DownloadFile(key)))
- {
- PdfConvertOptions options = new PdfConvertOptions();
- converter.Convert(outputFile, options);
- }
- }
- public static Stream DownloadFile(string key)
- {
- AmazonS3Client client = new AmazonS3Client();
- string bucketName = "my-bucket";
- GetObjectRequest request = new GetObjectRequest
- {
- Key = key,
- BucketName = bucketName
- };
- using (GetObjectResponse response = client.GetObject(request))
- {
- MemoryStream stream = new MemoryStream();
- response.ResponseStream.CopyTo(stream);
- stream.Position = 0;
- return stream;
- }
- }

Roshan RathodPosted Oct 2, 2020, 6:26 AM
Nice........