[英]Write Text in PDF in Hindi font using pdfbox
I want to write text in hindi font in pdf using pdf box. 我想使用pdf框以印地文字体将文本写成pdf。 Can anyone help.
谁能帮忙。
I am trying to write code like this. 我正在尝试编写这样的代码。
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(page);
PDFont font = PDTrueTypeFont.loadTTF( doc, new File("c:\\shusha.ttf"));
font.setFontEncoding(new WinAnsiEncoding());
PDPageContentStream content = new PDPageContentStream( doc, page, true, false );
content.setFont(font, 15);
content.beginText();
content.moveTextPositionByAmount( 200, 100 );
content.drawString( "Aamarsa" );
content.endText();
content.close();
doc.save( new FileOutputStream(new File("c:\\testOutput.pdf")));
doc.close();
Later I also tried to add encoding, but is not useful. 后来我也尝试添加编码,但是没有用。 I could not find any encoding class which supports UTF-8 in PDFBox.
我在PDFBox中找不到任何支持UTF-8的编码类。
Here i tried this, and got something what you want, use the same code, 在这里,我尝试了一下,并得到了想要的东西,使用相同的代码,
simply download the PDTrueTypeFont.java (from pdfbox-1.8.2-src.jar) file and include into your project, then modify the condition 只需下载PDTrueTypeFont.java(从pdfbox-1.8.2-src.jar)文件并将其包含到您的项目中,然后修改条件
before, 之前,
int platformEncoding = cmaps[i].getPlatformEncodingId();
if ( CMAPTable.ENCODING_UNICODE == platformEncoding)
modified, 改性,
int platformEncoding = cmaps[i].getPlatformEncodingId();
if ( CMAPTable.ENCODING_UNICODE == platformEncoding ||
CMAPTable.ENCODING_SYMBOL == platformEncoding)
because, this class not supporting the ENCODING_SYMBOL. 因为,该类不支持ENCODING_SYMBOL。 so only you are not able to create the pdf with different fonts.
因此,只有您不能使用不同的字体创建pdf。
Don't include the PDTrueTypeFont from the package pdfbox. 不要包括pdfbox包中的PDTrueTypeFont。 Use from your local package.
使用本地包装。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.