iText unicode in annotaion [英] iText unicode in annotaion

查看:185
本文介绍了iText unicode in annotaion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中使用Itext。

I'm using Itext in java.

请给我一个示例,将包含内容中的unicode字符串的文本注释添加到pdf。

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 in annotaion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆