java 设置pdf 编码_java – 使用itext将文本文件转换为pdf时设置编码

我正在努力让itext正确输出我的UTF-8编码文本,实际上输入文件包含像°和拉丁字符(é,è,à…)这样的符号.

但我没有找到解决方案这是我正在使用的代码:

BufferedReader input = null;

Document output = null;

System.out.println("Convert text file to pdf");

System.out.println("input : " + args[0]);

System.out.println("output : " + args[1]);

try {

// text file to convert to pdf as args[0]

input =

new BufferedReader (new FileReader(args[0]));

// letter 8.5x11

// see com.lowagie.text.PageSize for a complete list of page-size constants.

output = new Document(PageSize.LETTER,40,40);

// pdf file as args[1]

PdfWriter.getInstance(output,new FileOutputStream (args[1]));

output.open();

output.addAuthor("RealHowTo");

output.addSubject(args[0]);

output.addTitle(args[0]);

BaseFont courier = BaseFont.createFont(BaseFont.COURIER,BaseFont.CP1252,BaseFont.EMBEDDED);

Font font = new Font(courier,12,Font.NORMAL);

Chunk chunk = new Chunk("",font);

output.add(chunk);

String line = "";

while(null != (line = input.readLine())) {

System.out.println(line);

Paragraph p = new Paragraph(line);

p.setAlignment(Element.ALIGN_JUSTIFIED);

output.add(p);

}

System.out.println("Done.");

output.close();

input.close();

System.exit(0);

}

catch (Exception e) {

e.printStackTrace();

System.exit(1);

}

}

任何想法将不胜感激.

你可能感兴趣的:(java,设置pdf,编码)