The following code snippet shows how to convert a document from Azure Blob Storage:
packagecom.groupdocs.conversion.examples.advanced_usage.loading.loading_documents_from_different_sources;importcom.groupdocs.conversion.Converter;importcom.groupdocs.conversion.examples.Constants;importcom.groupdocs.conversion.exceptions.GroupDocsConversionException;importcom.groupdocs.conversion.options.convert.PdfConvertOptions;importcom.microsoft.azure.storage.CloudStorageAccount;importcom.microsoft.azure.storage.blob.CloudBlob;importcom.microsoft.azure.storage.blob.CloudBlobClient;importcom.microsoft.azure.storage.blob.CloudBlobContainer;importjava.io.ByteArrayInputStream;importjava.io.ByteArrayOutputStream;importjava.io.File;/**
* This example demonstrates how to download document from Azure Blob storage and convert document.
*/publicclassLoadDocumentFromAzureBlobStorage{publicstaticvoidrun(){StringblobName="sample.docx";StringconvertedFile="C:\\output\\converted.pdf";try{Converterconverter=newConverter(newByteArrayInputStream(DownloadFile(blobName).toByteArray()));PdfConvertOptionsoptions=newPdfConvertOptions();converter.convert(convertedFile,options);}catch(Exceptione){thrownewGroupDocsConversionException(e.getMessage());}System.out.print("\nSource document converted successfully.\nCheck output in "+convertedFile);}publicstaticfinalStringSTORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;"+"AccountName=Ram;"//Your account name.
+"AccountKey=key";//your account key.
publicstaticByteArrayOutputStreamDownloadFile(StringblobName)throwsException{CloudBlobContainercontainer=GetContainer();CloudBlobblob=container.getBlockBlobReference(blobName);ByteArrayOutputStreammemoryStream=newByteArrayOutputStream();blob.download(memoryStream);//memoryStream.Position = 0;
returnmemoryStream;}privatestaticCloudBlobContainerGetContainer()throwsException{StringcontainerName="***";CloudStorageAccountcloudStorageAccount=CloudStorageAccount.parse(STORAGE_CONNECTION_STRING);CloudBlobClientcloudBlobClient=cloudStorageAccount.createCloudBlobClient();CloudBlobContainercontainer=cloudBlobClient.getContainerReference(containerName);container.createIfNotExists();returncontainer;}}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.