你好,游客 登录 注册 搜索
背景:
阅读新闻

Android中生成PDF

[日期:2013-04-26] 来源:Linux社区  作者:拳四郎 [字体:大 中 小]

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。

linux
相关资讯       iText  Android生成PDF 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款