【问题标题】:Cannot read pdf generated by iText __OKBPDF无法读取由 iText __OKBPDF 生成的 pdf
【发布时间】:2013-03-27 01:01:13
【问题描述】:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.FileOutputStream;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;

import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;

    import com.itextpdf.text.pdf.PdfWriter;

public class MainActivity extends Activity {
    private static String FILE = "/HelloWorld.pdf";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
</i>

        try {
            Document document = new Document();
            boolean mExternalStorageAvailable = true;
            boolean mExternalStorageWriteable = false;
            String state = Environment.getExternalStorageState();

            if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            mExternalStorageAvailable = mExternalStorageWriteable = true;
            } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            // We can only read the media
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
            } else {
            // Something else is wrong. It may be one of many other states, but all we need
            //  to know is we can neither read nor write
            mExternalStorageAvailable = mExternalStorageWriteable = false;
            }
            String file = null;
            if(mExternalStorageWriteable) {
            file = Environment.getExternalStorageDirectory().getPath() + FILE;
            }

            PdfWriter.getInstance(document,new FileOutputStream(file));
            document.open();
            Paragraph p = new Paragraph("Hello iText World!");
            document.add(p);
            document.close();

            } catch (Exception e) {
            e.printStackTrace();
            }
    }


}

我正在尝试为另一组数据再生成一个,生成的文件大小为 0kb,打开时显示消息“Adobe Reader 无法打开“List.pdf”并键入或因为文件已损坏”。

【问题讨论】:

  • 您确定没有遗漏任何记录在 logcat 中的异常吗?乍一看,这段代码似乎是正确的。

标签: java android itext


【解决方案1】:

iText 需要许可证密钥。检查你的 logcat 是否有异常。访问他们的网站以获取许可证密钥并了解如何实施。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    相关资源
    最近更新 更多