相关疑难解决方法(0)

将Pdf页面转换为Android Java中的Bitmap

我需要将PDF文件(PDF页面)转换为Android中的位图(或图像文件).

1.使用Apache的Pdfbox jar.但是它使用了android中不支持的一些java类.2.尝试将图像转换为pdf的Itext jar(我需要它的反向操作)就像我尝试了很多罐子一样.但没有积极的结果.

byte[] bytes;
    try {

        File file = new File(this.getFilesDir().getAbsolutePath()+"/2010Q2_SDK_Overview.pdf");
        FileInputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();
        bytes = new byte[(int) length];
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }


        ByteBuffer buffer = ByteBuffer.NEW(bytes);
        String data = Base64.encodeToString(bytes, Base64.DEFAULT);
        PDFFile pdf_file = new PDFFile(buffer);
        PDFPage page = pdf_file.getPage(2);

        RectF rect = new RectF(0, …
Run Code Online (Sandbox Code Playgroud)

pdf android

38
推荐指数
3
解决办法
5万
查看次数

标签 统计

android ×1

pdf ×1