See the code for which I am getting this issue , My main concern is that after setting the font , I am getting the error in contentStream.showText() , so could anyone help me to set font for PDFBox which is supported in Ubuntu?
public class PDpage
{
public static void main(String args[]) throws IOException
{
PDDocument searchableDocument = new PDDocument();
String str2 = "/home/grid/Desktop/A.pdf";
try
{
String str = "/home/grid/Downloads/ubuntu-font-family-0.83/Ubuntu-C.ttf";
String str1 = "/home/grid/Desktop/a.txt";
File f = new File(str1);
String s = FileUtils.readFileToString(f);
PDPage page2 = new PDPage();
searchableDocument.addPage(page2);
PDPageContentStream contentStream = new PDPageContentStream(searchableDocument , page2);
PDFont font = PDType0Font.load(searchableDocument, new FileInputStream(str));
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(20,750);
contentStream.showText(s);
contentStream.endText();
contentStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
searchableDocument.save(str2);
searchableDocument.close();
}
}
Code shows the following error while running :
Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+000A in font UbuntuCondensed-Regular
at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:404)
at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:342)
at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:323)
at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:418)
at com.purpose.all.Strip.PDpage.main(PDpage.java:45)
How this code is similar to the question Can't insert Tabs and Spaces into PDBox PDF document ?