Hi Aspose,
I am trying to generate a PDF file using Aspose version 7.2 passing a styled HTML string, but when the PDF is generated styles appear broken.
The following is the piece of code I’m using.
public static byte[] GetPdfFromHtml(string html)
{
// Get the license
var license = new AsposeLicense();
license.SetLicense(@"D:\Data\Aspose.Total.lic");
// Instantiate an object PDF class
var pdf = new Pdf();
// add the section to PDF document sections collection
var section = pdf.Sections.Add();
// Create text paragraphs containing HTML text
// and enable the property to display HTML contents within their own formatting
var text = new Text(section, html);
text.IsHtmlTagSupported = true;
//Add the text paragraphs containing HTML text to the section
section.Paragraphs.Add(text);
// Specify the URL to find images
pdf.HtmlInfo.ImgUrl = WebUtil.GetFullUrl("/");
pdf.HtmlInfo.ExternalResourcesBasePath = WebUtil.GetFullUrl("/");
// Return bytes
using (var ms = new MemoryStream())
{
pdf.Save(ms);
return ms.ToArray();
}
}
This is Sample HTML string
<html>
<head>
<style>
body { margin: 0; padding: 0; }
body * { box-sizing: border-box; }
/* article pdf styling */
.article-pdf { padding-top: 148px; box-sizing: border-box; }
.article-pdf__logo-holder { position: absolute; top: 0; right: 40px; height: 143px; }
.article-pdf__title { color: #ffffff; display: inline-block; margin: 0; padding: 6px 0; font-family: sans-serif; font-size: 28px; font-weight: bold; background-color: #E2171F; margin-bottom: 32px; padding: 10px 30px 10px 40px; box-sizing: border-box; }
.article-pdf__content { font-family: sans-serif; font-size: 16px; }
.article-pdf__description { color: #17365D; font-size: 24px; font-family: serif; font-weight: bold; font-style: italic; }
.article-pdf__date { position: absolute; bottom: 0; right: 0; width: 100%; background-color: #ffffff; text-align: right; padding: 8px 40px; }
/* article pdf cols */
.article-pdf__col-wrapper { padding: 0 40px 40px; display: inline-block; width: 100%; }
.article-pdf__col { float: left; }
.article-pdf__col--left { width: 30%; padding-right: 20px; padding-top: 10px; }
.article-pdf__col--right { width: 70%; }
/* article copy */
.article-pdf p,
.article-pdf ul,
.article-pdf h2, h3, h4, h5, h6 { margin-bottom: 23px; }
.article-pdf ul,
.article-pdf ol { margin: 0 0 23px; padding: 0; }
.article-pdf ul li,
.article-pdf ol li { margin-bottom: 5px; }
.article-pdf h2, h3, h4, h5, h6 { font-family: sans-serif; font-weight: bold; color: #17365D; }
</style>
</head>
<body>
<article class="article-pdf">
<h1 class="article-pdf__title">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</h1>
<div class="article-pdf__col-wrapper">
<div class="article-pdf__col article-pdf__col--left">
<div class="article-pdf__description">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</div>
</div>
<div class="article-pdf__col article-pdf__col--right">
<div class="article-pdf__content"><p>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum <a href="https://www.google.com">Google</a>.</p></div>
</div>
</div>
<div class="article-pdf__date">29/10/2018</div>
<footer class="article-pdf__disclaimer">
This guidance was correct at publication 29/10/2018..
</footer>
</article>
</body>
</html>