HTML to PDF : CSS display:block

Hi,


I have been attempting to get an HTML file converting to PDF. I am using the Aspose.Words(v15.12.0) library.

I have greatly simplified the HTML file to demonstrate what I am trying to achieve. There is style set on the of the . I am forcing a line break between the
's.

Viewing the HTML file in browsers shows the line break working correctly, however when converting the HTML to PDF the style seems to be ignored? I saw there was an issue on using CSS selectors with Aspose, so I tried inline style on each
but that had the same result.

Is there something I am missing or a way to get output a PDF with the correct layout. Below is the HTML I am trying to convert.

body > table > tbody > tr > td {
display: block;
}
1 2 3 4 5

This is test code 1 using word library
Aspose.Words.Document doc = new Aspose.Words.Document(this.pickupTestLocation);
doc.Save(this.dropLocation);

This is another test code 2 using the PDF library
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(this.pickupTestLocation);

//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());

// 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);

if (File.Exists(this.dropLocation))
{
File.Delete(this.dropLocation);
}

//Save the pdf document
pdf.Save(this.dropLocation);

Thanks,
Charles



Hi Charles,


Thanks for your inquiry.

Please note that it is not guaranteed that the output Word/PDF document will look exactly the same as the input HTML. This is because Aspose.Words was originally designed to work with Microsoft Word documents and HTML documents are quite different.

However, Aspose.Words’ HTML engine tries to mimic the way the Microsoft Word works. To you, this means that if you convert HTML file into a Microsoft Word document or PDF using Aspose.Words, the output will appear almost exactly as if it was done by Microsoft Word. Moreover, I have attached two PDF documents (one generated by Aspose.Words and the other generated by Microsoft Word) here for your reference. The Two PDF files are identical.

If we can help you with anything else, please feel free to ask.

Best regards,

Thank you for the feedback Awais.


It makes sense, I think my first mistake was using the Word library to save to PDF when I should rather use the PDF library.

I have managed to sort myself out, the PDF just takes an incredibly long time to generate but I will look into that. If I don’t come right I will post for assistance in the Aspose.Pdf forum.

Thanks again,
Charles

Hi Charles,


Thanks for your inquiry. If you have any troubles, please feel free to post a query in any Aspose forum and we will be glad to look into this further for you.

Best regards,