Hi Aspose,
I’m try to generate PDF using inline HTML string. However the generated pdf is not same as HTML string which I provided (footer need to be loads at the very bottom of the full document).
Here the code snippet that I use to generation.
public static byte[] GetPdfFromHtml(string html, string mediaPath)
{
// Get the license
var asposeLicenseFileName = ConfigurationManager.AppSettings["AsposeLicPath"];
if (!string.IsNullOrEmpty(asposeLicenseFileName))
{
try
{
// instantiate the license class
var license = new AsposeLicense();
//pass only the name of the license file embedded in the assembly
license.SetLicense(asposeLicenseFileName);
}
catch (Exception ex)
{
// run as evaluation if this fails
NLogManager.LogGeneralError("Aspose PDF Generator",
"Could not load Aspose licence file. Please check the correct Aspose licence file : " + asposeLicenseFileName,
ex.Message);
}
}
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(html)), objLoadOptions);
// Return bytes
using (var ms = new MemoryStream())
{
doc.Save(ms);
return ms.ToArray();
}
}
Please refer attachement PDF Resources.zip (150.0 KB)
HTML string that providing : HTML_string.html
Generated PDf : PDF_Output.pdf
Aspose version : 20.11.0.0
I have updated this as mentioned in PDF Generated broken on inline styled HTML string
Thanks.