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

How to get Location with Wifi in Android?
Compare first two decimal points
How to open dialog window to edit user in jsf page
Spinner inside ActionBarCompact
Java log file parser on Windows 2008 is not able to use File.lastModified
How to turn an number into a roman numeral? [duplicate]
jsp populating object array
Possible to make an XML template for Android display different numbers of buttons?
Refreshing the table columns in jsp page on click of refresh button at each row using ajax/javascript
Best way to separate javascript and java in jsp
int field validation in swing for user registration form
Java - How to encoded MAC decoded font information
XML Schema file to String
Java - Object Without New Instance
Aligment of Jlabel dynamically created
Regular Expression: Replace except from specific characters and whitespace

Categories

HOME
mediawiki
mfc
layout
fft
relay
spring-cloud-stream
cmd
malloc
cross-browser
acquia
reveal.js
dax
row
alignment
moonmail
quartz-scheduler
fatal-error
apache-metamodel
reactive-cocoa
oracle-coherence
openedx
scichart
dbext
grails3
ml
physics-engine
tokenize
dcevm
xpages-ssjs
numerical-methods
pepper
apache-commons-io
info.plist
uninstall
typo3-6.2.x
log4js-node
javascriptcore
ecto
google-cloud-endpoints-v2
usbserial
webtest
windows-dev-center
http-referer
ios5
revolution-slider
disassembling
hockeyapp
unspecified
ssjs
uft-api
impersonation
particles.js
convertapi
long-polling
errordocument
rails-routing
git-diff
kbuild
media-player
flutterwave
arrow-keys
vtigercrm
gnome-shell-extensions
sts-springsourcetoolsuite
trash
impresspages
bstr
actionbardrawertoggle
python-stackless
ford-fulkerson
separator
t4mvc
ibaction
processmodel
sniffer
iiviewdeckcontroller
device-orientation
ng-animate
coldbox
winddk
android-imagebutton
wordpress-theme-customize
client-side-templating
gulp-less
code-access-security
starcluster
didselectrowatindexpath
resty-gwt
ember-charts
commoncrypto
soundtouch
tws
dataservice
orchardcms-1.7
sabredav
ocunit
bitsharp
ocx
osql
subscript
gnu-prolog
suppress
jquery-ui-droppable
asp.net-profiles
zend-tool
sef
exchange-server-2003
virtual-functions
anti-piracy
aquaticprime
w3wp
paul-graham

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