0

我的应用程序没有在 pdf 中加载图像,并且每次在 pdf 中加载包含图像的页面时都会出错。

这是 LogCat:

06-29 11:07:29.900: E/APV.PDFRenderer(468): image with unsupported colorspace ColorSpace[CMYK]
06-29 11:07:29.900: E/APV.PDFRenderer(468): java.lang.UnsupportedOperationException: image with unsupported colorspace ColorSpace[CMYK]
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFImage.parseData(PDFImage.java:319)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFImage.getImage(PDFImage.java:225)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFRenderer.drawImage(PDFRenderer.java:374)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFImageCmd.execute(PDFPage.java:654)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFRenderer.iterate(PDFRenderer.java:674)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.BaseWatchable.execute(BaseWatchable.java:263)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.BaseWatchable.go(BaseWatchable.java:197)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at com.sun.pdfview.PDFPage.getImage(PDFPage.java:237)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at net.sf.andpdf.pdfviewer.PdfViewerActivity.showPage(PdfViewerActivity.java:790)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at net.sf.andpdf.pdfviewer.PdfViewerActivity.access$12(PdfViewerActivity.java:769)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at net.sf.andpdf.pdfviewer.PdfViewerActivity$3.run(PdfViewerActivity.java:259)
06-29 11:07:29.900: E/APV.PDFRenderer(468):     at java.lang.Thread.run(Thread.java:1096)

这个代码:

第一个.java

package android.pdf.reader;

import java.io.File;
import java.io.FilenameFilter;

import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class First extends ListActivity {
    String LOGTAG="";
    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.main);

        File images = Environment.getExternalStorageDirectory();
        imagelist = images.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return ((name.endsWith(".pdf")));
            }
        });
        pdflist = new String[imagelist.length];
        for (int i = 0; i < imagelist.length; i++) {
            Log.e(LOGTAG,imagelist[i].getName());
            pdflist[i] = imagelist[i].getName();
        }
        this.setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, pdflist));
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String path = imagelist[(int) id].getAbsolutePath();
        Log.d(LOGTAG,path);
        openPdfIntent(path);
    }

    private void openPdfIntent(String path) {
        try {
            final Intent intent = new Intent(First.this,Second.class);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

二.java

package android.pdf.reader;

import net.sf.andpdf.pdfviewer.PdfViewerActivity;
import android.os.Bundle;

public class Second extends PdfViewerActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    public int getPreviousPageImageResource() {
        return R.drawable.left_arrow;
    }

    public int getNextPageImageResource() {
        return R.drawable.right_arrow;
    }

    public int getZoomInImageResource() {
        return R.drawable.zoom_in;
    }

    public int getZoomOutImageResource() {
        return R.drawable.zoom_out;
    }

    public int getPdfPasswordLayoutResource() {
        return R.layout.pdf_file_password;
    }

    public int getPdfPageNumberResource() {
        return R.layout.dialog_pagenumber;
    }

    public int getPdfPasswordEditField() {
        return R.id.etPassword;
    }

    public int getPdfPasswordOkButton() {
        return R.id.btOK;
    }

    public int getPdfPasswordExitButton() {
        return R.id.btExit;
    }

    public int getPdfPageNumberEditField() {
        return R.id.pagenum_edit;
    }
}

显现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.pdf.reader"
    android:versionCode="1"
    android:versionName="1.0" >

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".First"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Second"
            android:label="@string/app_name" >
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>

有什么建议么?

谢谢

4

1 回答 1

2

PDF 文件中的图像采用 CMYK 格式,您正尝试以不同的颜色空间(可能是 RGB)读取它们。

您的日志说不支持 CMYK,但 pdfViewer 中有一个名为 CMYKColorSpace 的类,所以也许这会有所帮助。

如果您发布代码,我可能会为您提供更多帮助。

编辑:

我正在阅读的文档实际上是原始库 com.sun.pdfview (我的错!)

andpdf的文档指出:

“该项目是来自 SUN 的使用 AWT 的 pdf-renderer 的一个端口。太糟糕了,Android 不支持 AWT,所以首先要做的是将 AWT-Objects 映射到 Android-Graphic-Objects”。

如果您点击链接,您将看到 Image 和 ColorSpace 尚未映射。所以 CMYK 还不支持。

于 2012-06-29T12:21:02.347 回答