tech.grasshopper.pdf.optimizer.TextContentSanitizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-pdf-report Show documentation
Show all versions of cucumber-pdf-report Show documentation
Generates Cucumber execution report in PDF format
package tech.grasshopper.pdf.optimizer;
import org.apache.pdfbox.pdmodel.font.PDFont;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class TextContentSanitizer {
private PDFont font;
public String sanitizeText(String text) {
StringBuffer strBuf = new StringBuffer();
try {
font.encode(text);
return text;
} catch (Exception e) {
char[] chars = text.toCharArray();
for (Character character : chars) {
try{
font.encode(character.toString());
strBuf.append(character);
} catch(Exception ex) {
strBuf.append("");
}
}
}
return strBuf.toString();
}
}