'in aspose Image CSS style is ignored and the image is rendered full size in the cell of table using .NET
I am experiencing some problem when inserting an html code containing images. The problem is that css information like width, height are ignored and the final pdf document always contains an image at 100% of its image size. how can I solve this problem?
var file = _contentService.GetFile(imgPathPassport.ContentServerId).Base64Content;
var htmTxt = @"‹img src='data:image/png; base64," + file + "' style='width:30px; height:40px;'>";
builder.InsertHtml(htmTxt);
Solution 1:[1]
As I can see image dimensions specified in img
element style
attribute is applied properly by the latest Aspose.Words version. Here is a simple code I used for testing:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string base64img = Convert.ToBase64String(File.ReadAllBytes(@"C:\Temp\test.png"));
builder.InsertHtml(string.Format("<img src=\"data:image/png; base64,{0}\" style=\"width:30px; height:40px;\" />", base64img));
doc.Save(@"C:\Temp\out.docx");
doc.Save(@"C:\Temp\out.pdf");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Alexey Noskov |