java


iText Output Missing Unicode Characters


I am using iText to generate PDFs out of java from java.awt.print.Printables.
It all works fine, just until one point:
The printables often contain various unicode characters (as they just do, I guess :-) ), for which I am using a composite Font with one extra fallback font in lib/fonts/fallback. In Java it all works fine with this solution.
When exporting it to PDF, I am already using my own FontMapper-Implementation:
public class PdfFontMapper implements FontMapper {
public BaseFont awtToPdf(Font font) {
try {
if(!font.getFamily().equalsIgnoreCase("Trebuchet MS")) {
return getBaseFontFromFile(SunFontManager.getInstance().getPlatformFontPath( true ), "ARIALUNI.ttf");
}
else {
return getBaseFontFromFile(SunFontManager.getInstance().getPlatformFontPath( true ), "Trebuchet MS.ttf");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public Font pdfToAwt(BaseFont baseFont, int size) {
throw new UnsupportedOperationException();
}
private BaseFont getBaseFontFromFile(String directory, String filename)
throws Exception {
InputStream is = null;
try {
final ClassLoader cl = Thread.currentThread()
.getContextClassLoader();
is = cl.getResourceAsStream(filename);
// is = IMappingApplication.class.getResourceAsStream(directory +
// filename);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
while (true) {
int size = is.read(buf);
if (size < 0) {
break;
}
bos.write(buf, 0, size);
}
buf = bos.toByteArray();
BaseFont bf = BaseFont.createFont(filename, BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED, BaseFont.NOT_CACHED, buf, null);
return bf;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (is != null) {
is.close();
}
}
}
}
, special thanks to G.J. Schouten.
But unfortunately, characters not included in my base font, "Trebuchet MS", don't get exported - they just go missing. Interestingly, if I only add one Font to the Mapper, "Arial Unicode", it works pretty fine.
Well, I could of course just use one font then. But I hope there is a better solution.
And by the way: The glyphs (Emojis) from my fallback-library always get rendered well. But I didn't get a solution to run in which I could only use a physical font + fallback-fonts in fonts/fallback.
Does anyone have an idea how to solve this?
Btw.: I already tried embedding the fonts with the PDF, but that didn't work (and I would think it's not necessary, since I am using pretty common fonts).
Greetings, Andy

Related Links

Generating intermediate vertices
Validating the Date format using selenium Webdriver
Get first number in comma separated string
javafx mac dmg deploy install location on Applications
How to set encoding of SOAP responses in CXF client?
Rotating tick mark labels to 45 degrees in JFreechart
Joining Array[Bytes] using Spark foreachPartition and ListBuffer
Thread running in debug mode, but doesn't work in real time
When maven dependency Version is whole number, exception while parsing
why Uiautomator crashes in getUiDevices()?
Connecting to remote Windows machine with JSch
Convert json into an object of a class that contains a template variable using gson
How to add extension to Client Hello HTTPS (okHTTP)
Java LocalDateTime from Spring Data JPA in loop
Which one is more safe from SQL injection-NamedParameterJdbcTemplate or SimpleJdbcTemplate?
Iterating through attributes of DIFFIRENT types in a class and printing each [duplicate]

Categories

HOME
java
ibm-bluemix
deployment
pypi
fluentd
mfc
angular-material
packages
podio
append
android-youtube-api
designer
quartz-scheduler
ghc
pugjs
normalizr
accessor
extjs5
captiveportal
php-openssl
angular2-aot
h2db
shopware
xpages-ssjs
qhull
xacml
atlassian-crucible
windowbuilder
srcset
gtrendsr
calibre
typed.js
grails-3.1
phpfreechat
normal-distribution
mmenu
jmonkeyengine
web-mining
mixture-model
occlusion
bootstrapper
ruby-on-rails-3.1
elmah
turbogears
http-redirect
galleria
qwt
dotcover
youcompleteme
clean-architecture
winscp-net
domain-model
pg-dump
epson
cudafy.net
titanium-android
orthogonal
word-vba-mac
google-feed-api
sts-springsourcetoolsuite
dstu2-fhir
phishing
multiple-regression
clang-static-analyzer
python-stackless
make-install
dataview
cloudbees
jfugue
iad
sdhc
feedback
purge
emailrelay
method-parameters
appfabric-cache
apache-commons-fileupload
fluid-dynamics
streambase
bridge.net
apache-commons-net
umbraco6
system.reflection
python-green
dia
clicktag
dd
id3v2
wordpress-theme-customize
rdl
php-5.4
xojo
starcluster
datagridviewcolumn
transcoding
message-driven-bean
dexterity
django-nonrel
mqx
spring-validator
viewswitcher
chrono
spring-portlet-mvc
php-parser
deobfuscation
yui-datatable
disclosure
meego
data-acquisition

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App