0

私はJavaでItextを使用しています。

コンテンツにUnicode文字列を含むテキスト注釈をPDFに追加する例を教えてください。

ありがとう。

4

1 に答える 1

1

これは、既存のPDFにテキスト注釈を追加する簡単なサンプルです。タイトルとテキスト注釈の内容の両方にアラビア文字が含まれています。

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();
    }
}

サンプル結果

于 2012-11-07T09:44:11.440 に答える