I am converting attached docx document to html fixed which retain all the formating and styling.
It converts the document decently, But the problem is I want to upload the image and shape on the cloud server and bind the uri of the uploaded image to respective <img src=“uri”. tag while converting it to html.
While converting doc to html fixed, Aspose create a folder and keep all the images, css and font winthin that folder But not all images like shape, diagrams, and charts are saved in that folder
where to find that images type ???
Also, custom shape, diagrams and charts don’t have HasImage property to true, so these type of images cannot be uploaded on the server any way around for it ??
Also, How to bind the uri of all types of images to respective <img src=“uri” tag while converting it to html fixed and loading all css and font??
In brief Point of concerns :
How to iterate through the docx and upload each images whether it is a diagram, shapes, charts or screenshot sequentially and upload it on the server to keep the image uri. Remember HasImage property is not true for custom shapes,diagrams and charts so such images type cannot be uploaded on the server any way around for it ?
How to bind uri of respective images to corresponding <img tag within html document while converting docx to html fixed type.
How to load css and font while loading html fixed document within the .net application.
P.S: I have attached a sample document with all the possible scenario and issues that I am facing with aspose.words. Refer attached sample document and provide code to resolve these issues.
You can use the code from to upload the images and then use uploaded images. FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType) will give you the types of the images.
Following code can be used to save any shape as image.
ShapeRenderer r = shape.GetShapeRenderer();
// Define custom options which control how the image is rendered. Render the shape to the JPEG raster format.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Emf) {
Scale = 1.5 f
};
// Save the rendered image to disk.
r.Save(dataDir + "TestFile.RenderToDisk Out.emf", imageOptions);
This doesn’t solve any of the problem. Did you tried using the attached document ?
To add some more details in the query, While converting docx containing shape, diagrams, and charts to html fixed type it generate “svg” image. Is there any way to extract “svg” from the html document and upload it on the cloud server in the form of image and bind the uri to respective <img src tag.
Again my POC are :
How to iterate through the docx and upload each images whether it is a diagram, shapes, charts or screenshot sequentially and upload it on the server to keep the image uri. Remember HasImage property is not true for custom shapes,diagrams and charts so such images type cannot be uploaded on the server any way around for it ?
How to bind uri of respective images to corresponding <img tag within html document while converting docx to html fixed type.
How to load css and font while loading html fixed document within the .net application.
Please read my query properly None of my query is answered. Could you please ask some senior person of person having expertise in aspose.words to look in to the issue.
Sorry for the delay. There are some limitations if you use Aspose.Words for .NET to convert to HtmlFixed format and it does not support CurrentShape property in ResourceSavingArgs and SVG to raster image during Word to HtmlFixed. We need these features to accomplish the task using Aspose.Words only.
Two new issues to support above mentioned features have been logged into our issue tracking system as WORDSNET-11693 and WORDSNET-11694 respectively. We will keep you updated on these issues in this thread.
However one solution is available if you use Aspose.Words and Aspose.Pdf. Aspose.Words can be used to convert Word to PDF and then Aspose.Pdf can be used to convert PDF to HTML . Following code can be used to convert PDF to HtmlFixed and save SVGs as raster images during conversion.
Document pdf = new Document("c:/pdftest/out.pdf");
string outHtmlFile = @"c:\pdftest\Out_FileConverted.html";
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.FixedLayout = true;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
pdf.Save(outHtmlFile, saveOptions);
You can use the following code to upload all or specific resources to cloud storage and update resource URI according to new location while saving to HtmlFixed format. HtmFixedSaveOptions.ExportEmbeddedSvg can be set to false to capture IResourceSavingCallback.ResourceSaving method for all shapes (which are rendered as SVG).
var fileName = @ "E:\Aspose\Defects\11694\Aspose test document.docx";
var outFileName = @ "E:\Aspose\Defects\11694\out.html";
Document doc = new Document(fileName);
var so = new HtmlFixedSaveOptions();
so.ExportEmbeddedSvg = false;
var callback = new ResourceSavingCallback();
so.ResourceSavingCallback = callback;
doc.Save(outFileName, so);
callback.UploadImagesToServer();
internal class ResourceSavingCallback: IResourceSavingCallback
{
private readonly Dictionary < string, Stream > mImages;
public ResourceSavingCallback() {
mImages = new Dictionary < string, Stream > ();
}
public void ResourceSaving(ResourceSavingArgs args)
{
if (args.ResourceFileName.EndsWith(".png") || args.ResourceFileName.EndsWith(".jpeg")) // TODO any other image types
{
args.ResourceFileUri = "wwww.myserver.com/" + args.ResourceFileName;
var stream = new MemoryStream();
args.ResourceStream = stream;
args.KeepResourceStreamOpen = true;
mImages.Add(args.ResourceFileName, stream);
}
}
public void UploadImagesToServer()
{
foreach(var pair in mImages)
{
// TODO upload images
Debug.WriteLine(pair.Key);
Debug.WriteLine(pair.Value.Length);
}
}
}