All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.grasshopper.pdf.optimizer.TextContentSanitizer Maven / Gradle / Ivy

There is a newer version: 2.14.0
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy