Open GoogleCodeExporter opened 9 years ago
nskclr wrote on 20.09.2007 20:11:36 +0200:
Hi
I installed ARIALUNI.TTF & tried with the code below.
ITextRenderer renderer = new ITextRenderer();
renderer.getFontResolver().addFont("C:\\WINNT\\Fonts\\ARIALUNI.TTF",
"UTF-8", BaseFont.NOT_EMBEDDED);
Still the pdf is incorrect. Do I need to change any pdf settings?
Thanks
Original comment by pdoubl...@gmail.com
on 16 Feb 2011 at 9:55
nskclr wrote on 21.09.2007 18:44:58 +0200:
Hi Pete
Thanks for your response.
From the flying saucer source, I got css for 4 locales. I need help to get the
css for other languages like chinese, korean, japanese etc.
Thanks
Original comment by pdoubl...@gmail.com
on 16 Feb 2011 at 9:55
pdoubleya wrote on 20.07.2008 19:29:06 +0200:
Deferring to R9.
Original comment by pdoubl...@gmail.com
on 16 Feb 2011 at 9:55
I've been able to render UTF-8 using code similar to the above but using
BaseFont.IDENTITY_H as the user guide shows.
Since fonts must be provided for UTF-8, I'd like to be able to provide a
classpath file (such as byte content) for the font file instead of a full file
path.
IText BaseFont supports creating fonts using the byte content as the param
ttfAfm, but defaults to using the file path when missing.
I attempted to create a custom FontResolver from ITextFontResolver, but too
many methods and inner classes are private
(for example getFontFamily() is public but it returns FontFamily which is
private)
For CSS, the url can be provided as relative but I believe it's still expected
to be relative to the current directory (based on NaiveUserAgent.resolveURI)
Original comment by matt.blanchette@gmail.com
on 2 Oct 2012 at 10:07
I was able to use the CSS approach, creating a custom user agent extending
ITextUserAgent and overriding resolveAndOpenStream() to also check the
classpath with getClassLoader().getResourceAsStream
For the CSS I used this for each of the files (changing the weight/style for
each to match the name):
@font-face {
font-family: "___";
src: url("fonts/___-Regular.ttf");
font-weight: normal;
font-style: normal;
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
Original comment by matt.blanchette@gmail.com
on 3 Oct 2012 at 3:19
@matt.blanchette@gmail.com, What did you use? I have tried using font-face in
css and also addFont function but i am not able to print the Chinese
characters, Can you please help me
Original comment by ankurmit...@gmail.com
on 17 Nov 2012 at 10:47
With the font-face CSS I mentioned before I also used the code below.
This loads the font files from the classpath (based on src url in CSS).
/**
* Allows overriding read/opening streams from URI to allow resolving fonts from classpath.
*/
public class FontResourceLoader extends ITextUserAgent {
public FontResourceLoader(ITextOutputDevice outputDevice) {
super(outputDevice);
}
@Override
protected InputStream resolveAndOpenStream(String uri) {
InputStream is = super.resolveAndOpenStream(uri);
// Allow resolving fonts from classpath
if( is == null && uri != null && uri.contains("fonts/") ) {
is = FontResourceLoader.class.getClassLoader().getResourceAsStream(uri);
}
return is;
}
}
ITextRenderer pdfRenderer = new ITextRenderer();
// Add custom user agent for resolving url resource lookups for fonts from
classpath
FontResourceLoader fontHandler = new
FontResourceLoader(pdfRenderer.getOutputDevice());
fontHandler.setSharedContext(pdfRenderer.getSharedContext());
pdfRenderer.getSharedContext().setUserAgentCallback(fontHandler);
Original comment by matt.blanchette@gmail.com
on 20 Jan 2014 at 3:19
Regarding loading fonts from the classpath:
If all you want to do is loading a specific font file from the classpath, you
do not need any special handlers, as iText 2.1.7 actually tries to load fonts
as a resource from the classpath as a last resort.
renderer.getFontResolver().addFont("/the/package/of/the/font.ttf",
BaseFont.IDENTITY_H, true);
will load the font from the classpath just fine.
In fact, if you do not want to use the CSS descriptor route detailed above,
this is the only way that does not require copying and hacking half the font
logic classes in iText to make it work.
Original comment by stot...@gmail.com
on 9 Oct 2014 at 2:20
Original issue reported on code.google.com by
pdoubl...@gmail.com
on 16 Feb 2011 at 9:55