繁体   English   中英

无法读取iText __OKBPDF生成的pdf

[英]Cannot read pdf generated by iText __OKBPDF

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,当打开时显示消息“ Adob​​e Reader无法打开“ List.pdf”,并且键入或因为文件已损坏”。

iText需要许可证密钥。 检查您的logcat是否有异常。 转到他们的站点以获取许可证密钥,并查看如何实现它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM