01 |
using iTextSharp.text; |
02 |
using iTextSharp.text.pdf; |
03 |
... |
04 |
private void button1_Click( object sender, EventArgs e) |
05 |
{ |
06 |
Document document = new Document(PageSize.A4); |
07 |
try { |
08 |
PdfWriter.GetInstance(document, new FileStream( "demo.pdf" , FileMode.Create)); |
09 |
document.Open(); |
10 |
BaseFont gothicbf = BaseFont.CreateFont( |
11 |
"c:\\windows\\fonts\\mingliu.ttc,0" , |
12 |
BaseFont.IDENTITY_H, |
13 |
BaseFont.EMBEDDED |
14 |
); |
15 |
iTextSharp.text.Font gothicfont = new iTextSharp.text.Font(gothicbf, 16, 0); |
16 |
String textg = "这是一个PDF测试页(细明体)\n此为参考iTextSharp Version=4.0.7.0制作" ; |
17 |
document.Add( new Paragraph(textg, gothicfont)); |
18 |
} |
19 |
catch (DocumentException de) { |
20 |
... |
21 |
} |
22 |
catch (IOException ioe) { |
23 |
... |
24 |
} |
25 |
finally { |
26 |
document.Close(); |
27 |
... |
28 |
} |
29 |
} |