Grunow, André (beeone extern) wrote:
I forgot to mention, that these 2 words could also be combined with a "-". Ergo: The 2 words must not be separated, even when there is a "blank" or a "-" between them.
OK, maybe the best solution is to use /u00a0 for non breaking spaces, and not to replace the hyphen, but to make sure it is not used as a split-character like is done in the attached (updated) code sample. br, Bruno
package test;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.SplitCharacter;
import com.lowagie.text.pdf.PdfChunk;
import com.lowagie.text.pdf.PdfWriter;
public class NonBreakingSpace implements SplitCharacter {
public static void main(String[] args) {
String string = "Look at this paragraph with a lot of different products and at least one product called Kautschuk-Plant, where the plant itself can be planted, on the other hand, there are some more words with absolutely no sense.";
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a writer
PdfWriter.getInstance(
// that listens to the document
document,
// and directs a PDF-stream to a file
new FileOutputStream("nbsp.pdf"));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph(string));
Chunk c = new Chunk(string);
c.setSplitCharacter(new NonBreakingSpace());
document.add(new Paragraph(c));
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
public boolean isSplitCharacter(int start, int current, int end, char[] cc,
PdfChunk[] ck) {
char c;
if (ck == null)
c = cc[current];
else
c = ck[Math.min(current, ck.length - 1)]
.getUnicodeEquivalent(cc[current]);
return (c == ' ');
}
}
nbsp.pdf
Description: Adobe PDF document
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
