开发者

Reading a pdf file using iText library [closed]

开发者 https://www.devze.com 2023-03-01 18:48 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 开发者_如何学运维11 years ago.

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.


try this

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

    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消