BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
Requirement |
Response |
Display list of files from blob server (.docx) if exists |
Add dropdown button in tittle bar which shows list of files available in App_Data folder.
|
Docx file can be edited and saved in blob server ( need to call API when clicked on save button)
|
Added option to save edited file back to 'App_Data' folder in web server.
|
Convert docx file in to PDF
|
Added option to save the document as PDF in 'App_Data' folder in web server.
|
// Import blob from Azure and convert it to Sfdt format
[HttpPost]
public HttpResponseMessage ImportBlob(string blobPath)
{
WebClient client = new WebClient();
//Download data from azure blob path as byte array
byte[] doc = client.DownloadData(blobPath);
//Convert byte array to stream
Stream stream = new MemoryStream(doc);
stream.Position = 0;
string type = "";
int index = blobPath.LastIndexOf('.');
type = index > -1 && index < blobPath.Length - 1 ? blobPath.Substring(index + 1) : "";
type = type.ToLower();
string json = "";
//If the file is in sfdt format we can directly open it in document editor
if (type == "sfdt")
{
StreamReader reader = new StreamReader(stream);
// Read content of stream as string
json = reader.ReadToEnd();
reader.Dispose();
}
else
{
// Convert word document to Sfdt format
WordDocument document = WordDocument.Load(stream, GetFormatType(type));
json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
document.Dispose();
}
stream.Dispose();
return new HttpResponseMessage() { Content = new StringContent(json) };
} |
public string SaveAsBlob([FromBody]DocumentInfo blobInfo)
{
string status = "";
try
{
string blobPath = blobInfo.blobPath;
Stream documentstrem = new MemoryStream(Convert.FromBase64String(blobInfo.blobContent.Split(',')[1]));
documentstrem.Position = 0;
SaveDocument(blobPath, documentstrem).GetAwaiter().GetResult();
status = "success";
}
catch
{
status = "failure";
}
return status;
}
internal async Task SaveDocument(string blobPath, Stream stream)
{
// Provide your Azure account name and key
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
// Provide blob name
CloudBlobContainer container = client.GetContainerReference(blobName);
//Get only the file path from azure URL
string filePath = blobPath.Replace("https://" + accountName + ".blob.core.windows.net/" + blobName + "/", "");
CloudBlockBlob blob = container.GetBlockBlobReference(filePath);
stream.Position = 0;
await blob.UploadFromStreamAsync(stream);
}
|
public class DocumentInfo
{
public string blobPath;
public string blobContent;
} |
public saveToBlob() {
this.documentEditor.saveAsBlob('Docx').then(function (blob) {
var fileReader = new FileReader();
fileReader.onload = function () {
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', '/api/DocumentEditor/SaveAsBlob', true);
httpRequest.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200 || httpRequest.status === 304) {
console.log(httpRequest.responseText);
}
}
}
var data = {
// Added azure path to save the blob
blobPath: documentPath,
blobContent: fileReader.result
};
httpRequest.send(JSON.stringify(data));
}
fileReader.readAsDataURL(blob);
});
}
|
//Get only blob path from azure URL
string filePath = blobPath.Replace("https://" + accountName + ".blob.core.windows.net/" +blobName + "/", "");
CloudBlockBlob blob = container.GetBlockBlobReference(filePath); |
public async Task SaveDocument(string blobPath, Stream stream) {
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudBlobClient client = account.CreateCloudBlobClient();
CloudBlobContainer container = client.GetContainerReference(blobName);
CloudBlockBlob blob = container.GetBlockBlobReference(blobPath);
stream.Position = 0;
await blob.UploadFromStreamAsync(stream);
} |
Syncfusion.DocIO.DLS.WordDocument wordDocument = newSyncfusion.DocIO.DLS.WordDocument(stream,Syncfusion.DocIO.FormatType.Docx);
DocToPDFConverter converter = new DocToPDFConverter();
PdfDocument pdf = converter.ConvertToPDF(wordDocument);
//Creates a certificate instance from PFX file with private key
PdfCertificate pdfCert = new PdfCertificate(certificatePath,"syncfusion");
//Creates a digital signature
PdfSignature signature = new PdfSignature(pdf, pdf.Pages[0], pdfCert,"Signature");
//Sets signature information
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
MemoryStream stream = new MemoryStream();
pdf.Save(stream);
pdf.Close(true);
wordDocument.Close();
string path =System.Web.HttpContext.Current.Server.MapPath("~/App_Data/");
FileStream fileStream = new FileStream(path + fileName,FileMode.OpenOrCreate, FileAccess.ReadWrite);
stream.Position = 0;
stream.CopyTo(fileStream);
stream.Close();
fileStream.Close();
return "Sucess"; |