ITEXT实例学习与研究(二) 之 创建一个细长的浅黄色背景的页面以及纵向页面与横向页面之间的切换
2012-02-17 17:44
537 查看
iTextSharp.text.Document-object共有三个构造函数:
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
int marginLeft,
int marginRight,
int marginTop,
int marginBottom);
第一个构造函数以A4页面作为参数调用第二个构造函数,第二个构造函数以每边36磅页边距为参数调用第三个构造函数
u 页面尺寸:
你可以通过指定的颜色和大小创建你自己的页面,下面的示例代码创建一个细长的浅黄色背景的页面:
Rectangle pageSize = new Rectangle(144, 720);
//pageSize.BackgroundColor = new Color(0xFF, 0xFF, 0xDE);
pageSize.setBorderColor(newBaseColor(0xFF, 0xFF, 0xDE));
Document document = new Document(pageSize);
通常,你不必创建这样的页面,而可以从下面页面尺寸中选择:
A0-A10, LEGAL, LETTER, HALFLETTER,_11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA 和 FLSE
大多数情况下使用纵向页面,如果希望使用横向页面,你只须使用rotate()函数:
Document document = new Document(PageSize.A4.rotate());
public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
int marginLeft,
int marginRight,
int marginTop,
int marginBottom);
第一个构造函数以A4页面作为参数调用第二个构造函数,第二个构造函数以每边36磅页边距为参数调用第三个构造函数
u 页面尺寸:
你可以通过指定的颜色和大小创建你自己的页面,下面的示例代码创建一个细长的浅黄色背景的页面:
Rectangle pageSize = new Rectangle(144, 720);
//pageSize.BackgroundColor = new Color(0xFF, 0xFF, 0xDE);
pageSize.setBorderColor(newBaseColor(0xFF, 0xFF, 0xDE));
Document document = new Document(pageSize);
通常,你不必创建这样的页面,而可以从下面页面尺寸中选择:
A0-A10, LEGAL, LETTER, HALFLETTER,_11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA 和 FLSE
import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter; public class Chap0102 { public static void main(String[] args) { System.out.println("Chapter 1 example 2: PageSize"); // step 1: creation of a document-object Rectangle pageSize = new Rectangle(144, 720); pageSize.setBackgroundColor(new java.awt.Color(0xFF, 0xFF, 0xDE)); Document document = new Document(pageSize); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream("Chap0102.pdf")); // step 3: we open the document document.open(); // step 4: we add some paragraphs to the document for (int i = 0; i < 5; i++) { document.add(new Paragraph("Hello World")); } } catch(DocumentException de) { System.err.println(de.getMessage()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); } }
大多数情况下使用纵向页面,如果希望使用横向页面,你只须使用rotate()函数:
Document document = new Document(PageSize.A4.rotate());
import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter; public class Chap0103 { public static void main(String[] args) { System.out.println("Chapter 1 example 3: PageSize"); // step 1: creation of a document-object Document document = new Document(PageSize.A4.rotate()); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileOutputStream("Chap0103.pdf")); // step 3: we open the document document.open(); // step 4: we add some phrases to the document for (int i = 0; i < 20; i++) { document.add(new Phrase("Hello World, Hello Sun, Hello Moon, Hello Stars, Hello Sea, Hello Land, Hello People. ")); } } catch(DocumentException de) { System.err.println(de.getMessage()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); } }
相关文章推荐
- ITEXT实例学习与研究(三) 发现了ITEXT问题 没有WATERMARK以及一些其他的问题
- iOS: 学习笔记实例, 用代码控制视图创建与切换
- ionic入门贴:ionic的引入以及创建一个典型的mobile页面
- SWING组件学习3:图片以及创建一个带有图片的按钮
- Spring实例学习第一步,创建数据库(附Spring3.0.5完整压缩包下载地址以及Spring3.0开发所需要的jar包)
- oracle学习.数据库实例的用户创建以及创建连接
- [Android实例] app引导页(背景图片切换加各个页面动画效果)(申明:来源于网络)
- [Android实例] ViewPager多页面滑动切换以及动画效果【转】
- 一个令人厌烦的模板页面----Freemarker 之横向排列和纵向排列
- 一个全屏页面切换实例
- 两个JSP页面之间如何传递一个对象?比如一个LIST或者HASHMAP?以及为什么有时候REQUEST.GETATTRIBUTE("NAME")取不到值?
- JXCELL实例学习与研究(六) 之 sheet的分页功能的实现,以及基本EXCEL公式的使用 以及补充函数说明
- 关于enum ,调用webservice,用户控件与主页面之间的交互,datsource属性,net面试题,反射类生成sql语句,URl重写一个小实例
- linux fork函数(创建一个与原来进程几乎完全相同的进程)学习实例
- 微软企业库4.1学习笔记(二)各功能之间的依赖关系以及对象创建
- 安卓学习第28天:使用Intent在活动之间传递数据以及Activity的生命周期实例
- 微软企业库4.1学习笔记(二)各功能之间的依赖关系以及对象创建
- 创建一个filter实例(transform filter)(好好学习学习)
- Sharepoint学习笔记---Sandbox Solution-- Full Trust Proxy--开发实例之(1、创建一个能访问DataBase的Full Trust Proxy)
- AS3.0 实例学习 熟悉addChild和removeChild在不同的swf之间的运用,以及loader的用法