在Android中使用iText生成PDF文件时出现ClassCast异常

时间:2013-02-06 13:11:44

标签: android itext fileinputstream

这是我的代码。我正在使用iText在android中创建PDF文件。当我运行我的应用程序时,它通过转发例外。

        File file = new File("itext-test.pdf");
        FileOutputStream fileout = new FileOutputStream(file);
        Document document = new Document();
        PdfWriter.getInstance(document, fileout);
        document.addAuthor("Me");
        document.addTitle("My iText Test");
        document.open();
        Chunk chunk = new Chunk("iText Test");
        Font font =new Font();
        font.setStyle(Font.UNDERLINE);
        font.setStyle(Font.ITALIC);
        chunk.setFont(font);
        chunk.setBackground(null, Color.CYAN, 0, 0, 0);
        document.add(chunk);
        Paragraph paragraph = new Paragraph();
        paragraph.add("Hello World");
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);
        Image image;
        try {
            image = Image.getInstance("world.gif");
            image.setAlignment(Image.MIDDLE);
            document.add(image);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        List list = new List(true, 15);
        list.add("ABC");
        list.add("DEF");
        document.add(list);
        document.close();

0 个答案:

没有答案