Flying Saucer font for unicode characters
For some reason it started working with following css and .ttf file, which was generated by face-kit-generator:
@font-face {
src: url('arialuni.ttf');
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
body {
font-family: Arial Unicode MS, Lucida Sans Unicode, Arial, verdana, arial, helvetica, sans-serif;
font-size: 8.8pt;
}
Weird thing is that if I put font into some folder, let say "fonts", it will find the font but characters won't be rendered.
PDF generation from HTML having multilingual text using flying-saucer+iText, Only Chinese fonts are working
The style you defined only apply to tag name
, and the Hindi and Japanese text is outside this tag. It is rendered with the default font, which does not support all unicode characters.
To fix the bug, you can change your style to use font "Arial Unicode MS" for all document:
body{font-family: "Arial Unicode MS";}
Flying Saucer: Chinese character rendered as a box in PDF
Replacement of a character by an empty square or rectangle usually means that the character is not defined in the font file, and the system doesn't find information to draw it.
In this case, the HTML and CSS code is correct, but the arialuni.ttf
file is incomplete.
For reference, the arialuni.ttf
should be ~23 MB.
Flying Saucer adding embedded font not working on tomcat
finally solved. in some places i was using
InputStream htmlIS = IOUtils.toInputStream(invoiceHtml);
instead
InputStream htmlIS = IOUtils.toInputStream(invoiceHtml, "UTF-8");
that caused problem.
HTML to PDF with cyrillic characters
This worked for me!
public static void main(String[] args) throws DocumentException, IOException, SAXException, ParserConfigurationException {
String htmlString = "<!DOCTYPE html>\n" + "<html lang=\"ru\">\n" + "<head>\n"
+ " <meta charset=\"UTF-8\"/>\n" + " <meta http-equiv=\"Content-Type\" content=\"text/html\"/>\n"
+ " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\n"
+ " <style type='text/css'> "
+ " * { font-family: Verdana; }/n"
+ " </style>/n"
+ "</head>\n"
+ "<body>\n" + " <h3>ПРЕДСТАВЛЕНИЕ</h3>\n" + "</body>\n" + "</html>";
String path = FileSystemView.getFileSystemView().getDefaultDirectory().getPath() + "/A.pdf";
OutputStream os = new FileOutputStream(path);
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("c:/windows/fonts/verdana.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
renderer.setDocumentFromString(htmlString);
renderer.layout();
renderer.createPDF(os);
os.close();
}
I think the trick is to add the CSS to the HTML and the font must match what you set on the PDF.
Related Topics
Negative Top Margin Not Working in Ie 8 or 9
Visual Studio Intellisense for Bootstrap via Cdn
CSS Scroll Snapping, Vertical Not Working
Bootstrap Navbar Collapse Media-Query on Custom Width
CSS Font-Size Changes When Font-Family Falls Back
How to Create a CSS3 Gradient in Opera
How to Tell Which Font Chrome Is Using
Text Field Not Working in Safari
Ckeditor - Prevent Adding Image Dimensions as a CSS Style
How to Prevent :After Pseudo Element from Being Read by Screen Readers
Tweaking Bootstrap 2.0 for Semantic Markup
Media Queries Not Working in Internet Explorer 11
Font-Variant: Small-Caps; Shows Different Font Sizes Using Chrome or Firefox
Why Does Z-Index: -1; Appear Above Z-Index: 1;