Op 21/05/2011 17:13, pdfengine schreef:
Thanks 1T3XT but if I only use one Chunk to store the whole paragraph like your example, I will get the same result as yours.The problem is I hope I can get the same good looking result as yours but I also need to highlight the word "UMBWX".
1. You are putting our goodwill to the test by not obeying the rules: http://lowagie.com/rule1 You are NOT subscribed to the mailing list so you are giving us boring administrative work. We need to "accept" or "reject" every question you post manually. Manual work like this keeps us from real, paid work. 2. You are putting our goodwill to the test by making allegations without proof. Did you read the documentation? If so, you know that ColumnText can be used in "text mode" or in "composite mode". I've adapted the example sent earlier to "text mode", and I've written a second example that uses "composite mode". I'm attaching the resulting PDFs. The word "international" is hyphenated correctly.
If it was our intention to test our patience, did we pass the test?
package examples.hyph; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.HyphenationAuto; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.hyphenation.Hyphenation; import com.itextpdf.text.pdf.hyphenation.Hyphenator; public class HyphenationExample { public static final String TEXT1 = "James Moffett of Scout International "; public static final String TEXT2 = "UMBWX"; public static final String TEXT3 = " shares Jain's reluctance to invest directly in China, but because of doubts over corporate governance and legal protection, not out of concern over economic growth. Therefore, while Moffett has avoided Chinese stocks entirely, unlike Jain he has specifically sought exposure to China's rapid growth through overseas stocks such as BHP Billiton and Komatsu."; public static void main(String[] args) throws DocumentException, IOException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("results/hyph.pdf")); document.open(); Hyphenator h = new Hyphenator("en", "US", 2, 2); Hyphenation a = h.hyphenate("International"); System.out.println(a); HyphenationAuto en = new HyphenationAuto("en", "US", 2, 2); Font font = new Font(); Font bold = new Font(FontFamily.HELVETICA, Font.UNDEFINED, Font.BOLD); Chunk ck1 = new Chunk(TEXT1, font); ck1.setHyphenation(en); Chunk ck2 = new Chunk(TEXT2, bold); ck2.setHyphenation(en); Chunk ck3 = new Chunk(TEXT3, font); ck3.setHyphenation(en); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setAlignment(Element.ALIGN_JUSTIFIED); ct.setSimpleColumn(36, 36, 216, 806); ct.addText(ck1); ct.addText(ck2); ct.addText(ck3); ct.go(); document.close(); } }
package examples.hyph; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.HyphenationAuto; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.hyphenation.Hyphenation; import com.itextpdf.text.pdf.hyphenation.Hyphenator; public class HyphenationExample2 { public static final String TEXT1 = "James Moffett of Scout International "; public static final String TEXT2 = "UMBWX"; public static final String TEXT3 = " shares Jain's reluctance to invest directly in China, but because of doubts over corporate governance and legal protection, not out of concern over economic growth. Therefore, while Moffett has avoided Chinese stocks entirely, unlike Jain he has specifically sought exposure to China's rapid growth through overseas stocks such as BHP Billiton and Komatsu."; public static void main(String[] args) throws DocumentException, IOException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("results/hyph2.pdf")); document.open(); Font font = new Font(); Font bold = new Font(FontFamily.HELVETICA, Font.UNDEFINED, Font.BOLD); HyphenationAuto en = new HyphenationAuto("en", "US", 2, 2); Paragraph p = new Paragraph(); p.setHyphenation(en); p.setAlignment(Element.ALIGN_JUSTIFIED); p.add(new Chunk(TEXT1, font)); p.add(new Chunk(TEXT2, bold)); p.add(new Chunk(TEXT3, font)); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(36, 36, 216, 806); ct.addElement(p); ct.go(); document.close(); } }
hyph.pdf
Description: Adobe PDF document
hyph2.pdf
Description: Adobe PDF document
------------------------------------------------------------------------------ What Every C/C++ and Fortran developer Should Know! Read this article and learn how Intel has extended the reach of its next-generation tools to help Windows* and Linux* C/C++ and Fortran developers boost performance applications - including clusters. http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php