Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用iText库读取pdf文件_Android - Fatal编程技术网

Android 使用iText库读取pdf文件

Android 使用iText库读取pdf文件,android,Android,我是android新手。我计划开发一个PDF查看器。我听说有一个叫做iText的库可以用来开发PDF查看器。请告诉我如何在Android上使用iText库,以及如何使用该库开发应用程序。试试这个 public class ReadAndUsePdf { private static String INPUTFILE = "c:/temp/FirstPdf.pdf"; private static String OUTPUTFILE = "c:/temp/ReadPdf.pdf";

我是android新手。我计划开发一个PDF查看器。我听说有一个叫做iText的库可以用来开发PDF查看器。请告诉我如何在Android上使用iText库,以及如何使用该库开发应用程序。

试试这个

public class ReadAndUsePdf {
    private static String INPUTFILE = "c:/temp/FirstPdf.pdf";
    private static String OUTPUTFILE = "c:/temp/ReadPdf.pdf";

    public static void main(String[] args) throws DocumentException,
            IOException {
        Document document = new Document();

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(OUTPUTFILE));
        document.open();
        PdfReader reader = new PdfReader(INPUTFILE);
        int n = reader.getNumberOfPages();
        PdfImportedPage page;
        // Go through all pages
        for (int i = 1; i <= n; i++) {
            // Only page number 2 will be included
            if (i == 2) {
                page = writer.getImportedPage(reader, i);
                Image instance = Image.getInstance(page);
                // here you can show image on your phone
            }
        }
        document.close();

    }

}
公共类ReadAndUsePdf{
私有静态字符串INPUTFILE=“c:/temp/FirstPdf.pdf”;
私有静态字符串OUTPUTFILE=“c:/temp/ReadPdf.pdf”;
公共静态void main(字符串[]args)引发DocumentException,
IOException{
文档=新文档();
PdfWriter writer=PdfWriter.getInstance(文档,
新文件outputstream(OUTPUTFILE));
document.open();
PdfReader reader=新PdfReader(输入文件);
int n=reader.getNumberOfPages();
PDF导入页面;
//浏览所有的页面
对于(inti=1;i试试这个

public class ReadAndUsePdf {
    private static String INPUTFILE = "c:/temp/FirstPdf.pdf";
    private static String OUTPUTFILE = "c:/temp/ReadPdf.pdf";

    public static void main(String[] args) throws DocumentException,
            IOException {
        Document document = new Document();

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(OUTPUTFILE));
        document.open();
        PdfReader reader = new PdfReader(INPUTFILE);
        int n = reader.getNumberOfPages();
        PdfImportedPage page;
        // Go through all pages
        for (int i = 1; i <= n; i++) {
            // Only page number 2 will be included
            if (i == 2) {
                page = writer.getImportedPage(reader, i);
                Image instance = Image.getInstance(page);
                // here you can show image on your phone
            }
        }
        document.close();

    }

}
公共类ReadAndUsePdf{
私有静态字符串INPUTFILE=“c:/temp/FirstPdf.pdf”;
私有静态字符串OUTPUTFILE=“c:/temp/ReadPdf.pdf”;
公共静态void main(字符串[]args)引发DocumentException,
IOException{
文档=新文档();
PdfWriter writer=PdfWriter.getInstance(文档,
新文件outputstream(OUTPUTFILE));
document.open();
PdfReader reader=新PdfReader(输入文件);
int n=reader.getNumberOfPages();
PDF导入页面;
//浏览所有的页面

对于(int i=1;i),我们可以回答有关库如何工作的特定问题,但我们不能告诉您如何编写整个应用程序。如果您的需求发生变化,请随意询问其他(更具体的)问题。我们可以回答有关库如何工作的特定问题,但我们无法告诉您如何编写整个应用程序。如果您的需求发生变化,请随时提出另一个(更具体)问题。如何显示com.itextpdf.text.Image对象?如何显示com.itextpdf.text.Image对象?