We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Css issues while converting to pdf

Hi,

I am trying to generate pdf with inline style in the html. But the alignments are not properly shown in the pdf.
Please look into the below html text.
table {
bOrder: 1px solid #E8EEF4;
bOrder-collapse: collapse;
}
table td {
bOrder: 1px solid #E8EEF4;
}
.mainDiv
{
width:100%;
height:100%;

}
.DivTopLeft1
{
height: 135px;
margin-left: 376px;
width: 365px;
}
}
.DivTopLeft2
{
height:135px;
width:365px;
}
.TableTopLeft2
{
margin-top: -140px;
}
.DivTopLeft3
{
height:135px;
width:365px;
}
.TableTopLeft3
{
margin-top: 25px;
}
.DivTopRight
{
height:135px;width:365px;
}
.TableTopRight
{
margin-top: 44px;
}
.DivBottom
{
height:235px;
}
.TableBottom
{
background-color:Aqua;
}

multipleTable


TopLeft1 Table
1 1
2 2
3 3
4 4
TopLeft2 Table
5 5
6 6
7 7
8 8
9 9
TopLeft3 Table
5 5
6 6
7 7
8 8
9 9
TopRight Table
cxc
BottomLeft Table
5 5
6 6
7 7
8 8
9 9
------------------------------
Below This is the code block

// Render the view html to a string.
string htmlText = this.htmlViewRenderer.RenderViewToString(this, viewName, model);

// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

//// Read the contents of HTML file into StreamReader object
//StreamReader r = File.OpenText(@“D:/pdftest/HTML2pdf.html”);
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, htmlText);
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
//Add the text paragraphs containing HTML text to the section
section.Paragraphs.Add(text2);

// Specify the URL which serves as images database
pdf.HtmlInfo.ImgUrl = “D:/pdftest/MemoryStream/”;
pdf.HtmlInfo.BadHtmlHandlingStrategy = BadHtmlHandlingStrategy.TreatAsPlainText;
pdf.HtmlInfo.ShowUnknownHtmlTagsAsText = true;
//Save the pdf document
pdf.Save(“D:/pdftest/MemoryStream/HTML2pdf.pdf”);
Thanks!

Hi Padmalatha,


Thanks for your inquiry. We have tested HTML to PDF conversion with new DOM approach using Aspose.Pdf for .NET 9.6.0 and unable to notice any issue. Please check following documentation link for the purpose. It will help you to fix the issue.


Please feel free to contact us for any further assistance.

Best Regards,

Hi,

The link given does not talk about text which has html tags in it.
Please not that above given code is to convert text with html tags passed but not a html file.

Thanks!

Hi Padmalatha,


Thanks for your feedback. Sorry for confusion, I thought you are reading html file in StreamReader and passing text to Text object in old generator. You can check following documentation link to add HTML string in PDF document. Hopefully it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,