阅读使用iText库PDF文件文件、iText、PDF

2023-09-13 02:13:40 作者:誓言べ如沙滩上的字

我是新来的机器人。我已经计划开发一个PDF阅读器。我听说有可用的库名为iText的开发PDF阅读器。请告诉我如何使用iText库与Android以及如何使用该库来开发应用程序。

I am new to android. I have planned to develop a PDF viewer. I heard that there is a library available called iText to develop PDF viewer. Please tell me how to use the iText library with Android and how to develop the application using that library.

推荐答案

试试这个

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();

    }

}