CSS does not apply to creating pdf from ABC pdf

advertisements

Problem:

I am passing HTML and creating pdf through ABC pdf.

But the CSS are not applied on the content and pdf created is not as expected.

Here is my code can u please suggest what is the problem or how we can apply CSS...

    public static String CreateHtmlFile(String strHtmlCode)
    {
        String Modifiedhtml = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html class="" _Telerik_IE9"" xmlns=""http://www.w3.org/1999/xhtml"">" + strHtmlCode;
        Modifiedhtml = Modifiedhtml.Remove(Modifiedhtml.IndexOf(@"//<![CDATA["), (Modifiedhtml.IndexOf("//]]>") - Modifiedhtml.IndexOf(@"//<![CDATA[")));
        string[] stringSeparators = new string[] { "PdfCreator" };
        var baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries).First();
        Modifiedhtml = Modifiedhtml.Replace(@"href=""../", (@"href=""" + baseUrl));
        Modifiedhtml = Modifiedhtml.Replace(@"href=""/", (@"href=""" + baseUrl));
        Doc theDoc = new Doc();
        theDoc.HtmlOptions.UseScript = false;
        //theDoc.Width = 1125;
        String s = string.Empty;
        //s = File.ReadAllText(@"D:\test.html");
        theDoc.Page = theDoc.AddPage();
        int theID;
        theID = theDoc.AddHtml(strHtmlCode);
        //theID = theDoc.AddHtml(s);
        while (true)
        {
            theDoc.FrameRect(); // add a black border
            if (!theDoc.Chainable(theID))
                break;
            theDoc.Page = theDoc.AddPage();
            theID = theDoc.AddImageToChain(theID);
        }
        for (int i = 1; i <= theDoc.PageCount; i++)
        {
            theDoc.PageNumber = i;
            theDoc.Flatten();
        }
        theDoc.Save(@"D:\two\pagedhtml4.pdf");
        theDoc.Clear();
        return String.Empty;
    }

strHtmlCode is the HTML of the page which we have to convert in PDF.

Thanks in advance


From the WebSupergoo doc page on the AddHtml Function:

Adds a block of HTML styled text to the current page.

HTML styled text does not support CSS. For full featured, standard CSS, you want AddImageHtml.