  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | JSP - A mailing list about Java Server Pages specification and reference | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | How to set font for text using ColumnText? | How to set font for text using ColumnText? 2006-09-07 - By daniel.lehtihet@(protected)
Back Hi list,
i can't seem to force a certain font and font size to be active when adding text directly to a PDF. I have tried the following code (below). Whatever i do, the font used in the pdf is always Arial 12.
Please advice
kind regards
Daniel
HTMLWorker worker = new HTMLWorker(document); StyleSheet style = new StyleSheet(); // stylesheet loadStyles( style ); StringReader sr = new StringReader( fieldValue ); ArrayList array = HTMLWorker.parseToList(sr,style); float[] position = af.getFieldPositions( bodyFieldName ); int n = reader.getNumberOfPages(); // we retrieve the size of the first page Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); PdfContentByte cb = stp.getOverContent((int)position[0]); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, 11); // alltid vara 11 punkters times-new-roman ColumnText ct = new ColumnText( cb ); ct.setSimpleColumn(position[1], position[4], position[3], position[2]); Element el = null; for (int idx = 0; idx < array.size(); idx++) { el = (Element)array.get(idx); ct.addElement( el ); } // read-only af.setFieldProperty( bodyFieldName ,"setfflags", PdfFormField.FF_READ_ONLY, null); ct.go();
<br><font size=2 face="sans-serif"><br> Hi list,</font> <br> <br><font size=2 face="sans-serif">i can't seem to force a certain font and font size to be active when adding text directly to a PDF. I have tried the following code (below). Whatever i do, the font used in the pdf is always Arial 12. </font> <br> <br><font size=2 face="sans-serif">Please advice</font> <br> <br><font size=2 face="sans-serif">kind regards</font> <br> <br><font size=2 face="sans-serif">Daniel</font> <br> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> HTMLWorker worker = new HTMLWorker(document); </font> <br><font size=2 face="sans-serif"> StyleSheet style = new StyleSheet(); // stylesheet</font> <br><font size=2 face="sans-serif"> loadStyles( style );</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> StringReader sr = new StringReader( fieldValue );</font> <br><font size=2 face="sans-serif"> ArrayList array = HTMLWorker.parseToList(sr,style); </font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> float[] position = af.getFieldPositions( bodyFieldName );</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> int n = reader.getNumberOfPages();</font> <br><font size=2 face="sans-serif"> // we retrieve the size of the first page</font> <br><font size=2 face="sans-serif"> Rectangle psize = reader.getPageSize(1);</font> <br><font size=2 face="sans-serif"> float width = psize.height();</font> <br><font size=2 face="sans-serif"> float height = psize.width();</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> PdfContentByte cb = stp.getOverContent((int)position[0]); </font> <br><font size=2 face="sans-serif"> BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT _EMBEDDED);</font> <br><font size=2 face="sans-serif"> cb.setFontAndSize(bf, 11); // alltid vara 11 punkters times-new-roman </font> <br><font size=2 face="sans-serif"> ColumnText ct = new ColumnText( cb ); </font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> ct.setSimpleColumn(position[1], position[4], position[3], position[2]);</font> <br><font size=2 face="sans-serif"> Element el = null;</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> for (int idx = 0; idx < array.size(); idx++)</font> <br><font size=2 face="sans-serif"> {</font> <br><font size=2 face="sans-serif"> el = (Element)array.get(idx);< /font> <br><font size=2 face="sans-serif"> ct.addElement( el ); </font> <br><font size=2 face="sans-serif"> }</font> <br><font size=2 face="sans-serif"> </font> <br><font size=2 face="sans-serif"> // read-only</font> <br><font size=2 face="sans-serif"> af.setFieldProperty( bodyFieldName ,"setfflags", PdfFormField.FF_READ_ONLY, null); </font> <br><font size=2 face="sans-serif"> ct.go();</font> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- 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 iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions
|
|
 |