OnClick里面的代码有点小复杂,要用的的话直接粘就可以了,注意修改相应的变量名,classname对应对就是操作itext生产pdf的类。
在包里面再创建两个测试类:
HelloWorld.java
package com.example.itexttest;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
/**
* Generates a simple 'Hello World' PDF file.
*
* @author blowagie
*/
public class HelloWorld {
/**
* Generates a PDF file with the text 'Hello World'
*
* @param args
* no arguments needed here
*/
public static void main(String[] args) {
System.out.println("Hello World");
// step 1: creation of a document-object
Document document = new Document();
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(Android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "iTextTest" + java.io.File.separator + "HelloWorld.pdf"));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
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();
}
}
生产Pdf如下:

Rotating.java(创建图片,并旋转)
注意再sdcard的根目录里面放一张图片,改名jxk_run.png。
