use of com.itextpdf.io.source.PdfTokenizer in project i7j-pdfsweep by itext.
the class PdfCleanUpTool method parseDAParam.
private Map<String, List> parseDAParam(PdfString DA) throws IOException {
Map<String, List> commandArguments = new HashMap<String, List>();
PdfTokenizer tokeniser = new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(DA.toUnicodeString().getBytes(StandardCharsets.UTF_8))));
List currentArguments = new ArrayList();
while (tokeniser.nextToken()) {
if (tokeniser.getTokenType() == PdfTokenizer.TokenType.Other) {
String key = tokeniser.getStringValue();
if ("RG".equals(key) || "G".equals(key) || "K".equals(key)) {
key = "StrokeColor";
} else if ("rg".equals(key) || "g".equals(key) || "k".equals(key)) {
key = "FillColor";
}
commandArguments.put(key, currentArguments);
currentArguments = new ArrayList();
} else {
switch(tokeniser.getTokenType()) {
case Number:
currentArguments.add(new PdfNumber(new Float(tokeniser.getStringValue())));
break;
case Name:
currentArguments.add(new PdfName(tokeniser.getStringValue()));
break;
default:
currentArguments.add(tokeniser.getStringValue());
}
}
}
return commandArguments;
}
Aggregations