Lee wrote:
IThese texts include Chinese characters, but I don't know
how to set their font style as bold or italic.

Document doc = new Document(new iTextSharp.text.Rectangle(564, 351)); PdfWriter writer= PdfWriter.GetInstance(doc, new FileStream(HttpContext.Current.Server.MapPath("1.pdf"), FileMode.Create)); doc.Open(); PdfContentByte cb = writer.DirectContent; cb.BeginText();

For Western font families, you'd use the bold or italic font;
I assume that you don't have a simheibd.ttf, simheii.ttf or simheibi.ttf

BaseFont bfont = BaseFont.CreateFont(@"c:\windows\fonts\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//Chinese font Heiti

When you don't have bold, italic or bold italic fonts for Heiti,
you'll have to mimic bold and/or italic.

cb.SetFontAndSize(bfont, 18); cb.SetCharacterSpacing(1); cb.SetRGBColorFill(66, 00, 00);

// simulate bold
cb.setLineWidth(0.5);
cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
// simulate italic
cb.setTextMatrix(1, 0, 25, 1, 0, 0);

cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "??????100,70???????????? ??", 100, 70,0);//Show Chinese character by absolute position cb.EndText(); doc.Close();

The suggestions I made, came from the top of my head.
I strongly suggest NOT to use showTextAligned, but to use the
ColumnText object to position your text.

That way, you can work with high level objects such as Paragraph,
Phrase and Chunk. Chunk has methods setSkew() and setTextRenderingMode()
that are easier to use than having to set the text matrix, line widths,
etc... Because if you change the "graphics state" like this, you need
to reset it (I suggest using saveState() and restoreState() if you want
to stick to using showTextAligned).
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to