Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Inline css in string variable filled with html text does not get displayed correctly in PDF.

$
0
0

We have a custom action in SharePoint 2013 on a custom list that leads to a page that generates a pdf via the Aspose.PDF .NET dll (downloaded latest version of Aspose.Total DLL's last week).

In the code behind of the page we gather the info of the item we need and convert it to a pdf.

In SharePoint a rich text multi line field can contain a lot of inline styling. A title can be displayed as<span style="Color:#F000000;font-family:Comic Sans MS;">Title<span>. But when we convert it to the pdf the inline styling of the span is not displayed. It does not have the correct color or font. We need some help on this one.

Below are the most import pieces of the code we use to generate the pdf.

 

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

Aspose.Pdf.Generator.Section section = new Aspose.Pdf.Generator.Section();

string text = SPHttpUtility.HtmlDecode(item[fldText.InternalName].ToString().Replace("&#160;", "<br>"));

string cssBeginText = @"<!DOCTYPE HTML"">

                                       <HTML>

                                       <HEAD>

                                       <LINK REL=StyleSheet HREF=""" + url + @"/_layouts/15/Hubo_CustomAction_Print/MinimalStyling.css"">

                                       </HEAD>

                                       <BODY>";

string cssEndText = @"</BODY></HTML>";

text = cssBeginText + text + cssEndText;

Aspose.Pdf.Generator.Text body = new Aspose.Pdf.Generator.Text(text);

body.TextInfo.FontName = fontBody;

body.IsHtmlTagSupported = true;

body.TextInfo.IsFontEmbedded = true;

body.TextInfo.FontSize = fontziseBody;

section.Paragraphs.Add(body);

               pdf.Sections.Add(section);

               pdf.Save(@"overzicht.pdf", SaveType.OpenInAcrobat, Response);


 


Viewing all articles
Browse latest Browse all 3131

Trending Articles