如果我同时使用以下两行代码,则尝试用iText 5替换pdf中的空格:
stream.setData(new String(data).replaceAll("\\s+"," ").getBytes());
或
stream.setData(new String(data).replaceAll(" ","").getBytes());
它生成损坏的pdf。 完整代码:
if (object instanceof PRStream) {
PRStream stream = (PRStream) object;
byte[] data = PdfReader.getStreamBytes(stream);
stream.setData(new String(data).replaceAll("\\s+"," ").getBytes());
}
有什么主意吗?
答案 0 :(得分:0)
以此更改您的代码
stream.setData(new String(data).replace(" ","").getBytes());
代替此行
stream.setData(new String(data).replaceAll("\\s+"," ").getBytes());