pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Attila Kiss <kiss.attila1...@gmail.com>
Subject character spacing
Date Thu, 15 Sep 2016 14:29:16 GMT
Hi everyone,
I've been trying to generate a pdf file using pdfbox.
I have worked with 1.8.11 but I have to deal with unicode texts, so I must
change the version to 2.0.0
I don't know if there is an instant solution for text align (I couldn't
find any), but I have a solution, wich does the thing:

for (String line : lines) {
   float charSpacing = 0;

   if (line.length() > 1) {
       float size = fontSize * font.getStringWidth(line) / 1000;
       float freeSpace = paragraphWidth - size;
       if (freeSpace > 0) {
           charSpacing = freeSpace / (line.length() - 2);
       }
   }
   if (lines.indexOf(line) + 1 != lines.size()) {//last line does not need
to be justify

     //it is because my locale settings
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator('.');
    symbols.setGroupingSeparator(',');
    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(symbols);
contentStream.appendRawCommands(format.format(charSpacing) + " Tc\n");
}
contentStream.drawString(line);
   contentStream.moveTextPositionByAmount(0, - rowHeight);

}
My problem is, in the new version the .appendRawCommands() method is
depricated. I can use it for now, but I wonder if it is depricated, what
can I use instead? Or how can accomplish the justified text align?
Any ideas are welcome!
Regards,
Attila

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message