Bcakground colour and borders and alignment is not coming in pdf generated by itextsharp

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bcakground colour and borders and alignment is not coming in pdf generated by itextsharp

RakeshN
This is my Html Page




same export as pdf using Itestsharp is getting displayed as





I am converting Html string to bytes, then i am converting bytes to pdf file
Method to convert to bytes from html



public byte[] ConvertHtmltoPDFByte(string pageHtml)
        {
            byte[] bytes;
            using (var memoryStream = new MemoryStream())
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.Append(pageHtml);
                var pdfDoc = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 10f, 0f);
                var htmlParser = new HTMLWorker(pdfDoc);
                var stringReader = new StringReader(stringBuilder.ToString());
                PdfWriter.GetInstance(pdfDoc, memoryStream);
                pdfDoc.Open();
                htmlParser.Parse(stringReader);
                pdfDoc.Close();
                bytes = memoryStream.ToArray();
                memoryStream.Close();
            }
            return bytes;
        }

is there any other ways to get pdf as exactly as html with styles and colours