Convert, using Aspose PDF for Java, an HTML document that includes several external CSS resources, into a PDF document.
We currently use PrinceXML to convert HTML and CSS into a PDF document. The process is relatively simple and works as follows:
- Generate HTML
- Feed said HTML into the PrinceXML engine
- Get a PDF
Since PrinceXML support both CSS2.1 and CSS3, we are able to leverage the following at-rules to control how the document looks:
PrinceXML also implemented custom directives (a DSL) on-top the CSS engine, providing support controlling margins, pagination, headers, and footers in a declarative fashion. Support for standard CSS makes it simple to manage generating a PDF only using HTML and CSS.
Challenges with an Aspose
Aspose for PDF supports the workflow described above however, there are enough deficiencies that make it impossible to generate PDFs from HTML and CSS alone. These include:
- No support for @page CSS at-rule
- No support for @media CSS at-rule
- No support for controlling margins and orientation using CSS alone (must be done after creating the document)
The lack of support for the first two rules make it impossible support headers and footers from CSS (for example, using @media print). Instead, one has to generate the content first and then inject the headers and footers manually on each page. Additionally, supporting page numbers can only be done after creating the document.
Additionally, multi-byte languages don’t render correctly in the final document.
- Will support for @page and @media be added any time in the near future?
- Will support for multi-byte languages be improved?