Free Support Forum - aspose.com

HTML to PDF CSS rendering in not consistent through out the PDF

Hi,
I am try to generate a pdf from html string or a html file but the CSS is not rendering consistent through out the PDF. My Html has table and the border for table are dark for some rows and column while lite for others. I have used two approach for this and i am getting same result from both approach.

My First Approach:

StringBuilder html = new StringBuilder();

string PdfHtmlTemplateHead = @"";
html.Append(PdfHtmlTemplateHead);
html.Append(File.ReadAllText(“E:\CSS\PdfCOOPPremManulifeCss.css”));
string PdfHtmlTemplateBody = @" HTML TABLE HERE ";
html.Append(PdfHtmlTemplateBody);

  		HtmlLoadOptions objLoadOptions = new HtmlLoadOptions();
            objLoadOptions.PageInfo.Margin.Bottom = 10;
            objLoadOptions.PageInfo.Margin.Top = 30;
            objLoadOptions.PageInfo.Margin.Left = 10;
            objLoadOptions.PageInfo.Margin.Right = 10;
            objLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;

            Document doc = new Document(new MemoryStream(Encoding.UTF8.GetBytes(html.ToString())), objLoadOptions);
            string FileName = "Sample_" + DateTime.Now.ToString("dd-MM-yyyy") + ".pdf";
            //Save PDF file on local hard drive or database or as you wish          
            doc.Save(@"E:\Aspose\" + FileName);

My Second approach:

String basePath = @“E:\CSS2”;
HtmlLoadOptions objLoadOptions = new HtmlLoadOptions(basePath);
objLoadOptions.PageInfo.Margin.Bottom = 10;
objLoadOptions.PageInfo.Margin.Top = 30;
objLoadOptions.PageInfo.Margin.Left = 10;
objLoadOptions.PageInfo.Margin.Right = 10;
objLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;

            //Load HTML string into MemoryStream using Aspose document class
            Document doc = new Document(@"E:\CSS2\testqc.html", objLoadOptions);
            string FileName = "Sample_" + DateTime.Now.ToString("dd-MM-yyyy") + ".pdf";
            //Save PDF file on local hard drive or database or as you wish          
            doc.Save(@"E:\Aspose\" + FileName);

I am using this piece of CSS to apply border in my table:

table, tr{
border: 1px solid black;
border-collapse: collapse;
}

But the output is not consistent. I am attaching screenshot of the output.aspose_output.PNG (62.1 KB)

@PankajToshiwal,

Can you please share source files along with generated PDF so that we may further investigate to help you out.

Hi Please find the Source file and sample pdf. Same pdf is generated from both approach.Aspose.zip (106.0 KB)

@PankajToshiwal,

We have tested the scenario in our environment and were able to notice the issue. We have logged it as PDFNET-47540 in our issue tracking system. We will further look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.