import java.awt.Graphics2D;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.AsianFontMapper;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
String text = "\u5e73\u548C";
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(100, 50);
AsianFontMapper mapper = new AsianFontMapper(AsianFontMapper.JapaneseFont_Min,
AsianFontMapper.JapaneseEncoding_H);
Graphics2D g2 = tp.createGraphics(100, 50, mapper);
java.awt.Font font = new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 12);
g2.setFont(font);
g2.drawString(text, 0, 40);
g2.dispose();
cb.addTemplate(tp, 36, 780);
document.close();
}
}
|