您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 其它办公文档 > iText中文教程(含代码)
iText中文教程(含代码)iText中文教程(含代码)...................................................1第一部分iText的简单应用.................................................2(一切实例代码来致于:)............2第一章创建一个Document...............................................2第一步创建一个Document实例:....................................4第二步创建Writer实例...........................................18第三步打开Document..............................................24第四步添加内容..................................................32第五步,关闭document............................................33第二章块、短句和段落................................................33块...............................................................33短句.............................................................34段落.............................................................35字体的延续.......................................................36第三章锚点、列表和注释..............................................38锚点.............................................................38列表.............................................................39注释.............................................................40第四章页眉页脚、章节、区域和绘图对象................................42页眉页脚.........................................................42章节和区域.......................................................42图形.............................................................43第五章表格..........................................................44一些简单的表格...................................................44一些表格参数.....................................................45大表格...........................................................48内存管理.........................................................49嵌套表格.........................................................49表格偏移.........................................................49表格的绝对位置...................................................50第六章图片..........................................................50Image对象........................................................50图片的位置.......................................................51缩放和旋转图片...................................................52原始图片数据.....................................................53System.Drawing.Bitmap............................................54TIFF和CCITT.....................................................54图片和其他对象...................................................55第二部分其他文档格式....................................................56第七章XML和(X)HTML.................................................56第八章RTF文件.......................................................56RTF包............................................................57创建一个RTF文档.................................................57不支持的特性.....................................................57RTF中扩展的页眉和页脚............................................58第三部分iText的高级应用................................................59第九章字体..........................................................59TrueType字体应用.................................................60TruType字体集合的应用............................................60第十章图象和文本的绝对位置..........................................61pdfContentByte...................................................61简单图形.........................................................62文本.............................................................62模板(FormxObjects)............................................63分栏.............................................................65PdfTable.........................................................66颜色(SpotColors)和图案(Patterns)...............................68第十一章本地和异地转向、目标和概要..................................68本地转向.........................................................68异地转向.........................................................68第一部分iTextiTextiTextiText的简单应用(一切实例代码来致于:)第一章第一章第一章第一章创建一个创建一个创建一个创建一个DocumentDocumentDocumentDocument利用iText五步创建一个PDF文件:helloword。第一步,创建一个iTextSharp.text.Document对象的实例:Documentdocument=newDocument();第二步,为该Document创建一个Writer实例:PdfWriter.getInstance(document,newFileStream(Chap0101.pdf,FileMode.Create));第三步,打开当前Documentdocument.Open();第四步,为当前Document添加内容:document.Add(newParagraph(HelloWorld));第五步,关闭Documentdocument.Close();完整的代码见示例代码0101。在例中,不难看出,制作一个PDF文件是非常简单的。注:如果你将例中“document.Add(newParagraph(HelloWorld));”中的字符串“HelloWord”换成中文,如“这是我的第一个PDF文件”,产生的结果一定让你大失所望,因为生成的PDF文件中并没有将中文显示出来,不要担心,在第9章中要专门讲解字体问题,中文显示也就迎刃而解了,如果不能正确显示中文,也就没有必要翻译本文了。publicclassHelloWorld{/***GeneratesaPDFfilewiththetext'HelloWorld'**@paramargsnoargumentsneededhere*/publicstaticvoidmain(String[]args){System.out.println(HelloWorld);//step1:creationofadocument-objectDocumentdocument=newDocument();try{//step2://wecreateawriterthatlistenstothedocument//anddirectsaPDF-streamtoafilePdfWriter.getInstance(document,newFileOutputStream(HelloWorld.pdf));//step3:weopenthedocumentdocument.open();//step4:weaddaparagraphtothedocumentdocument.add(newParagraph(HelloWorld));}catch(DocumentExceptionde){System.err.println(de.getMessage());}
本文标题:iText中文教程(含代码)
链接地址:https://www.777doc.com/doc-4390002 .html