让我们考虑这段代码:
public class Test1{
public static void CreatePdf(String src) throws IOException, COSVisitorException{
PDRectangle rec= new PDRectangle(400,400);
PDDocument document= null;
document = new PDDocument();
PDPage page = new PDPage(rec);
document.addPage(page);
PDDocumentInformation info=document.getDocumentInformation();
PDStream stream= new PDStream(document);
info.setAuthor("PdfBox");
info.setCreator("Pdf");
info.setSubject("Stéganographie");
info.setTitle("Stéganographie dans les documents PDF");
info.setKeywords("Stéganographie, pdf");
content= new PDPageContentStream(document, page, true, false );
font= PDType1Font.HELVETICA;
String hex = "4C0061f"; // shows "La"
//Notice that we have 00 between 4C and 61 where 00 =null character
StringBuilder sb = new StringBuilder();
for (int count = 0; count < hex.length() - 1; count += 2)
{
String output = hex.substring(count, (count + 2));
int decimal = Integer.parseInt(output, 16);
StringBuilder ae= sb.append((char)decimal);
}
String tt=sb.toString();
content.beginText();
content.setFont(font, 12);
content.appendRawCommands("15 385 Td\n");
content.appendRawCommands("("+tt+")"+"Tj\n");
content.endText();
content.close();
document.save("doc.pdf");
document.close();
}
我的问题是:为什么PDF文档中的“00”被替换为空格而不是空字符?请注意,我得到了这个空字符的宽度 0.0,但它在 PDF 文档中显示为一个空格!因此我得到:“ La”而不是“La”