Hi Aspose,
I having an issue when generate pdf using inline html string.
This happen on below attached html file.
InputHtmlFile.zip (5.2 KB)
Code snippet
public static byte[] GetPdfFromHtml(string htmlString, string mediaPath, string fileName)
{
// Get the license
var asposeLicenseFileName = @"~\Asserts\Aspose.Total.lic";
if (!string.IsNullOrEmpty(asposeLicenseFileName))
{
try
{
// instantiate the license class
var license = new License();
//pass only the name of the license file embedded in the assembly
license.SetLicense(asposeLicenseFileName);
}
catch (Exception ex)
{
// run as evaluation if this fails
}
}
var objLoadOptions = new HtmlLoadOptions(mediaPath);
objLoadOptions.PageInfo.Margin.Bottom = 10;
objLoadOptions.PageInfo.Margin.Top = 30;
objLoadOptions.PageInfo.Margin.Left = 10;
objLoadOptions.PageInfo.Margin.Right = 10;
var doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(htmlString)), objLoadOptions);
doc.Info.Title = fileName;
var emptyPageNumbers = new List<int>();
for (var pageNo = 1; pageNo <= doc.Pages.Count;)
{
if (doc.Pages[pageNo].IsBlank(0.01d))
{
emptyPageNumbers.Add(pageNo);
}
pageNo++;
}
if (emptyPageNumbers.Count > 0)
{
//Remove Empty Pages
doc.Pages.Delete(emptyPageNumbers.ToArray());
}
// Return bytes
using (var ms = new MemoryStream())
{
doc.Save(ms, SaveFormat.Pdf);
return ms.ToArray();
}
}
Output result
My-Sample-20210310100331.pdf (188.0 KB)
Can you please help to solve this.
Please let me know if you needed more details to investigate this issue.
Thanks,
Iresha