Hi! i am trying to add css code inline inside the tags and using the style tag in the header, i dont really understand why i can use color and background-color but no code that changes the format in any way like width, flexbox, float, margin etc are being rendered. why is that ? is there any work around for it
Can you please share which Aspose API are you using? Also, please share your sample HTML along with the sample code snippet so that we can test the scenario in our environment and address it accordingly.
Its aspose.words.
you can try with this example code, try render it in notepad and then convert it and you can see the side element goes back.
C# code:
public string ConvertHTMLToPdfBytes(byte[] document)
{
using (MemoryStream docStream = new MemoryStream(document))
{
LoadOptions lo = new LoadOptions();
lo.LoadFormat = LoadFormat.Html;
Document doc = new Document(docStream, lo);
// Save the document as PDF into a stream.
using (MemoryStream pdfStream = new MemoryStream())
{
doc.Save(pdfStream, SaveFormat.Pdf);
// Get base64 string from the resulting stream.
string pdfBase64String = Convert.ToBase64String(pdfStream.ToArray());
return pdfBase64String;
}
}
}
HTML:
<!DOCTYPE html>
<html>
<head>
<style>
.parent-container {
display: flex;
justify-content: space-between;
width: 100%
}
.child-element {
display: flex;
align-items: center;
}
.child-title {
margin-right: 10px;
}
.child-element .status {
margin-left: auto;
}
</style>
</head>
<body>
<div class="parent-container">
<h1 class="child-title"> datadatadatadatadatadata(15610) </h1>
<div class="child-element">side element</div>
</div>
</body>
</html>
@henrikJohansen93 Aspose.Words behavior is expected in this case, this is not a defect. In this case Aspose.Words fully mimics MS Word behavior. Here are output PDF documents produced by Aspose.Words and by MS Word:
ms.pdf (7.1 KB)
out.pdf (31.1 KB)
Please note, Aspose.Words is designed to work with MS Word documents. HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one format to another.
Regarding your HTML, there is no direct analog of DIV
elements in MS Word documents, usually the DIV
s are converted to paragraphs in Aspose.Words DOM.