How to add PDFBox to an Android project or suggest alternative

前端 未结 3 1924
情歌与酒
情歌与酒 2020-11-30 02:47

I\'m attempting to open an existing pdf file and then add another page to the pdf document from within an Android application. On the added page, I need to add some text and

相关标签:
3条回答
  • 2020-11-30 03:02

    i think the library class files are not included in the apk file. The library classes need to be converted into dex files then only it will be detected.please refer http://developer.android.com/guide/developing/building/index.html

    0 讨论(0)
  • 2020-11-30 03:15

    PDFBox uses java awt and swing, even for non UI tasks, I've tried to remove references but there are a lot of files, and I was removing too much stuff

    I've just tested PDFjet http://pdfjet.com/os/edition.html it's bsd licensed (plus commercial version with more features), with this sample code (ripped from Example_03.java) I was able to convert a jpeg to a pdf

        FileOutputStream fos = null;
        try
        {
            fos = new FileOutputStream("/sdcard/sample.pdf");
            PDF pdf = new PDF(fos);
            InputStream f = getApplicationContext().getAssets().open("img0.jpg"); 
            Image image = new Image(pdf, f, ImageType.JPEG);
            Page page = new Page(pdf, A4.PORTRAIT);
            image.setPosition(0, 0);
            image.drawOn(page);
            pdf.flush();
            fos.close();
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    

    I found the link here http://java-source.net/open-source/pdf-libraries

    0 讨论(0)
  • 2020-11-30 03:20

    Android Port of PDFBox

    There's a free Android Port of PDFBox available here:

    https://github.com/TomRoush/PdfBox-Android

    0 讨论(0)
提交回复
热议问题