Hiii
In here I am using css to wrap images. Now I am getting an issue.
my expected outcome is expectedOutcome.PNG.jpg (304.6 KB)
current outcome is CurrentOutput.PNG.jpg (242.2 KB)
my html HTML.zip (2.9 KB)
please use your own images
//this is my convert method
public List<byte[]> Convert(ContentsDto content, IDictionary<string, string> options, Func<DependentContent, Task<ContentsDto>> GetDependency = null)
{
License htmlLicense = new License();
htmlLicense.SetLicense("Aspose.Total.NET.lic");
var pdfBytearray = new List<byte[]>();
HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions() { CustomLoaderOfExternalResources = ResourceLoading, HtmlMediaType = HtmlMediaType.Print };
htmlLoadOptions.PageInfo.Margin.Left = 50;
htmlLoadOptions.PageInfo.Margin.Right = 50;
htmlLoadOptions.PageInfo.Margin.Top = 50;
htmlLoadOptions.PageInfo.Margin.Bottom = 50;
htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
htmlLoadOptions.PageInfo.Width = 959.976;
htmlLoadOptions.PageInfo.Height = 540;
//Manipulate html document
HtmlDocument htmlDocument = new HtmlDocument();
using (var htmlStream = new MemoryStream(content.Data))
{
htmlDocument.Load(htmlStream);
AddFroalaCSSSupport(htmlDocument);
foreach (HtmlNode p in htmlDocument.DocumentNode.SelectNodes("//p"))
{
if (p.ChildNodes.Count == 1 && p.InnerHtml== "<br>")
{
p.Remove();
}
}
}
using (var htmlOutputStream = new MemoryStream())
{
//convert html to pdf
htmlDocument.Save(htmlOutputStream);
htmlOutputStream.Seek(0, System.IO.SeekOrigin.Begin);
Document pdfDocument = new Document(htmlOutputStream, htmlLoadOptions);
//convert pdf to pptx
PptxSaveOptions pptx_save = new PptxSaveOptions();
using (var pptxStream = new MemoryStream())
{
pdfDocument.Save(pptxStream, pptx_save);
pptxStream.Seek(0, System.IO.SeekOrigin.Begin);
pdfBytearray.Add(pptxStream.ToArray());
}
}
return pdfBytearray;
}
//this is my added css method
private static void AddFroalaCSSSupport(HtmlDocument htmlDocument)
{
var linknode = htmlDocument.CreateElement("link");
linknode.SetAttributeValue("href", "https://cdnjs.cloudflare.com/ajax/libs/froala-editor/3.2.6/css/froala_editor.pkgd.min.css");
linknode.SetAttributeValue("rel", "stylesheet");
var htmlHead = htmlDocument.DocumentNode.SelectSingleNode("//head");
htmlHead.AppendChild(linknode);
//TODO : add this node from GE and remove this code
var bodyNode = htmlDocument.DocumentNode.SelectSingleNode("//body");
var bodyContent = bodyNode.InnerHtml;
var newBody = $"<div class=\"fr-view\">{bodyContent}</div>";
bodyNode.InnerHtml = newBody;
}
Do you have any solution to get that expected outcome???
In here HtmlDocument means HTML agility pack. we load our content(html) to that agility pack.
So HtmlNode,DocumentNode are it’s methods.
from AddFroalaCSSSupport() this method I am create a link node to put the css link as href .
this is my style sheet https://cdnjs.cloudflare.com/ajax/libs/froala-editor/3.2.6/css/froala_editor.pkgd.min.css
from this style sheet, we are wrapping images which has class=“fr-fil” (class=“fr-fic fr-dii fr-fil”)