Hi i am using spire to convert doc to html, i see below options
1. SaveToFile: This generate, Folder with images, css file, html. This we can not use, as we are trying to do this with azure func and local file generation is not supported here.
2. SaveToStream: This generate stream with html code. Here we are facing below issue ("doc1.html")
-> link to image is broken
-> Header and footer is missing from converted html files in some cases, i have attached the (doc1.docx) word file for which it is not getting generated.
-> unable to process doc1.doc file, getting error " System.InvalidOperationException: This is not a structured storage file." File name, doc1.doc is attached in this post.
Please find the below code using for this purpose. Here, we are looking to generate proper blob html stream which will display image properly.
string cnn = "xxxxxxxx";
string containerName = "xxxxxxxxx";
BlobServiceClient blobServiceClient = new BlobServiceClient(cnn);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
var blobs = containerClient.GetBlobs();
foreach (BlobItem blobItem in blobs)
{
//convert .docx files
if (blobItem.Name.Contains(".docx") || blobItem.Name.Contains(".doc"))
{
MemoryStream html = new MemoryStream();
BlobClient blobClient = containerClient.GetBlobClient(blobItem.Name);
if (blobClient.ExistsAsync().Result)
{
using (var docx = new MemoryStream())
{
blobClient.DownloadTo(docx);
//return ms.ToArray();
using (MemoryStream stream = new MemoryStream(docx.ToArray()))
{
Document spireDoc = new Document();
if (blobItem.Name.ToLower().Contains(".docx"))
{
spireDoc.LoadFromStream(stream, FileFormat.Docx2013);
}
else
{
spireDoc.LoadFromStream(stream, FileFormat.Doc);
}
//the new docx without image
spireDoc.SaveToStream(html, FileFormat.Html);
html.Position = 0;
blobClient = containerClient.GetBlobClient(
blobItem.Name.ToLower().Contains(".docx") ?
blobItem.Name.Replace(".docx", ".html") : blobItem.Name.Replace(".doc", ".html"));
await blobClient.UploadAsync(html, true);
}
}
}
}
}