注释中的 iText Unicode [英] iText unicode in annotaion
本文介绍了注释中的 iText Unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Java 中使用 Itext.
I'm using Itext in java.
请举个例子,给pdf添加一个包含unicode字符串的文本注释.
Please give me an example to add a text annotation which contains unicode string in content to pdf.
谢谢.
推荐答案
这里是一个向现有 PDF 添加文本注释的简单示例;文本注释的标题和内容均包含阿拉伯字符.
Here a simple sample adding a text annotation to an existing PDF; both the title and the content of the text annotation contain arabic characters.
import java.io.*;
import junit.framework.TestCase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.*;
public class TestAnnotations extends TestCase
{
// a phonetic approximation
final static String LAWRENCE_OF_ARABIA = "\u0644\u0648\u0631\u0627\u0646\u0633\u0627\u0644\u0639\u0631\u0628";
public void testUnicodeAnnotation() throws Exception
{
final PdfReader origPdfReader = new PdfReader("test.pdf");
final OutputStream outputStream = new FileOutputStream("test-annot.pdf");
final PdfStamper pdfStamper = new PdfStamper(origPdfReader, outputStream, '\0', true);
Rectangle rect = new Rectangle(100, 100);
PdfAnnotation annotation = PdfAnnotation.createText(pdfStamper.getWriter(), rect, LAWRENCE_OF_ARABIA, LAWRENCE_OF_ARABIA, true, "Help");
pdfStamper.addAnnotation(annotation, 1);
pdfStamper.close();
outputStream.close();
}
}
这篇关于注释中的 iText Unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文