Hi
Currently we are generating dynamic html to pdf in C# but external css(demo.css) are not applying to the generated pdf
Could you please help on below code
below are the sample code we are using Spire.Pdf(5.6.3.18046 version) and Spire.Doc(7.6.2.18046 version).
using Spire.Doc;
using Spire.Pdf;
using Spire.Pdf.HtmlConverter;
public bool PDFConvert()
{
string htmlCode = "<html><head><link href="demo.css" /></head><body>"<div class="centersection row margin-right-20"><p class="title-bold font-20 color-red"> this is a sample dynmic html to pdf </p></div>"</body></html>";
PdfDocument pdf = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = false;
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;
byte[] buffer;
Thread thread = new Thread(() =>
{
pdf.LoadFromHTML(htmlCode, true, setting, htmlLayoutFormat);
using (MemoryStream ms = new MemoryStream())
{
/*Default File for Preview of PDF */
using (FileStream to_stream = new FileStream("sampledemo.pdf", FileMode.Create, FileAccess.Write))
{
pdf.SaveToStream(ms, Spire.Pdf.FileFormat.PDF);
ms.WriteTo(to_stream);
buffer = ms.ToArray();
to_stream.Close();
ms.Close();
System.IO.File.WriteAllBytes(@"C:\SampleDemo\sampledemo.pdf", buffer);
}
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
return true;
}
sample file FYI... DEMO.css
.centersection
{
align:center;
}
.margin-right-20
{
margin-right:20px;
}
.title-bold
{
font-type:bold;
}
. font-20{
font-size:20px;
}
.color-red
{
color:red;
}