<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Now I want to read this css file and I want use this file while converting html to pdf. How can I include this css in aspose APIS? To let you know I will get HTML string from third party API and will use this html string to convert into PDF.
I can also get test.css file as binary from third party API, is there any to API in aspose which reads binary format css and will apply when converting?
@ramesh676 There is no way to feed CSS file to Aspose.Words before loading HTML. However, you can implement IResourceLoadingCallback and load CSS file while loading HTML document.
I have implemented IResourceLoadingCallback and I am able to load external css but I have one observation when I run the same CSS and HTML in browser I am seeing proper styling applied as below
But when I send same HTML and CSS to aspose and after converting it to PDF, in the generated PDF the styling is getting broken as below
Also the for the same CSS and HTML the svg icons are loading properly on browser as below
but when I converted my html css to PDF using aspose my svg icon is coming differently as below
does aspose support all css like css3 , css2 or other like SCSS.
@ramesh676 Could you please attach the problematic input and output documents here for testing? We will check the issue and provide you more information.
Also, please note, Aspose.Words is designed to work with MS Word documents at first. While loading HTML document, it is converted to Aspose.Words DOM and due to differences in HTML documents and MS Word documents object models it is not always possible to provide 100% fidelity after processing HTML document. When loading HTML document, Aspose.Words in most cases mimics MS Word behavior, not browser behavior.
If run above html in chrome then 64 number and para text will come side by side. If I process this html via aspose words to pdf format then I am seeing issue mentioned in above post i.e. 64 number will come up and para text will come down. I want the same look that we see in chrome. Could you let me know why aspose words is unable to process correct CSS with above HTML?
When I process above HTML- via aspose words my output pdf should look like below
@ramesh676 Aspose.Words in this case mimics MS Word behavior. If you convert the attached HTML document to DOCX or PDF using MS Word the result will be the same: ms.docx (12.5 KB) aspose.docx (7.8 KB)
So this is not a bug in Aspose.Words, it is expected behavior.
@ramesh676 You can try using Aspose.HTML to convert HTML to PDF, it is designed to work with HTML documents and should render HTML as it is rendered in the browser. But it is better to test the behavior on your side with your documents.
Could you please verify the conversion of above HTML to pdf using Apose HTML. I do not have aspose html code handy to process the document. Could you please process above html and share me the output file using aspose html for java? I tried online conversion and i am getting some unknown error so please do the needful so that I can proceed further to buy proper license.
We tested the scenario using both Aspose.HTML and Aspose.PDF for Java in our environment with the latest versions available.
With Aspose.HTML for Java, we faced java.lang.RuntimeException and this issue has been logged as HTMLJAVA-1595 in our issue tracking system for further analysis.
With Aspose.PDF for Java, we were able to generate the output attached below. However, the alignment was not correct in the generated PDF. Therefore, a ticket as PDFJAVA-43161 has been generated in order to rectify this issue.