HTML to PDF Batch Mode Converter that Respects CSS's @font-face?

☆樱花仙子☆ 提交于 2019-12-23 05:39:06

问题


NOTES: My request covers software or libraries, hence why I'm posting here. I also checked the similar threads here, but they asked for something subtly different.

I have the following HTML page:

<html>
<head>
   <link rel="stylesheet" type="text/css" href="font.css">
   <style>
      body {
        font-family: "Gotham SSm A";
        font-size: 22px;
      }
   </style>
</head>
<body>
   SUMMARY
</body>
</html>

And the font definition in font.css (truncated for brevity):

@font-face { 
   font-family: "Gotham SSm A"; 
   src: url(data:font/truetype;base64,...) format('truetype'); 
   font-weight:700; 
   font-style:italic; 
}

The page shows up fine in the browser, and when printed to PDF from the browser, is rendered fine as well. However, every utility I used to generate a PDF from server-side software (PHP) failed:

  1. Wkhtmltopdf, PhantomJS and PrinceXML didn't show the correct font (the latter gave a warning about not parsing all the CSS rules).

  2. SlimerJS failed to render, opened windows, and had unacceptable dependencies

  3. pandoc only converts to LaTeX and requires different utilities (on Windows/Linux) to go to PDF. What's more, it's LaTeX conversion (according to the online version I trie) messed up the fonts as well.

What are my alternatives? I need this to...

1. Respect modern CSS (including @font-face).
2. Be available on Windows & Linux with similar output on both
3. Be offline (utility or library is fine)
4. Allow commercial use
5. Be cost effective (preferably free)

回答1:


Have a look at PrinceXML.

It meets all your technical requirements. It is free for private use (I don't know pricing levels when used commercially).




回答2:


callas software (watch it, I'm affiliated with this company!) has a technology they have been working on called pdfChip which will do this perfectly. It's not free, but it will handle HTML + CSS + Javascript using a simple command-line tool. And it can generate good, print-ready PDF (including PDF/X, metadata, professional color spaces, bar codes and more...).

I can't point you to a URL yet as it's going to be released in January 2015, but send me a private message if you want to see whether it would work.



来源:https://stackoverflow.com/questions/27320249/html-to-pdf-batch-mode-converter-that-respects-csss-font-face

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!