我的应用程序没有加载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)
这个代码:
First.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();
}
}
}
Second.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>
有什么建议吗?
由于
答案 0 :(得分:2)
PDF文件中的图像是CMYK,您尝试在不同的颜色空间(可能是RGB)中读取它们。
你的日志说不支持CMYK,但pdfViewer中有一个名为CMYKColorSpace的类,所以这可能会有所帮助。
如果您发布代码,我可以为您提供更多帮助。
编辑:
我正在阅读的文档实际上是原始库com.sun.pdfview(我的不好!)
andpdf的documentation表示:
“该项目是SUN使用AWT的pdf渲染器的一个端口。 太糟糕了,Android不支持AWT,所以要做的第一件事就是将AWT-Objects映射到Android-Graphic-Objects“。
如果您点击链接,您会看到Image和ColorSpace尚未映射。所以CMYK尚不支持。