我試圖生成一個簡單的PDF並將其傳遞給Google雲打印,但是當我嘗試將PDF打印到我的谷歌驅動器時沒有任何反應。 (登錄作品) 我怎麼會認證我的PDF是完整且有效的,對於初學者?我覺得我正在考慮iText的話。iText /雲打印不能在Android上工作
另外,我得到一些錯誤,告訴我,
public class PDFViewer extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.getWindow().setSoftInputMode
(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
super.onCreate(savedInstanceState);
InputStream object = this.getResources().openRawResource(R.raw.itextkey);
LicenseKey.loadLicenseFile(object);
File root = Environment.getExternalStorageDirectory();
File f = new File(android.os.Environment.getExternalStorageDirectory()
.getAbsolutePath() + java.io.File.separator + "HelloWorld.pdf");
boolean externalStorageAvailable = false;
boolean externalStorageWriteable = false;
String state = Environment.getExternalStorageState();
// if we can read and write to storage
if (Environment.MEDIA_MOUNTED.equals(state)) {
externalStorageAvailable = true;
externalStorageWriteable = true;
}
// else if we can read but cannot write
else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
externalStorageAvailable = true;
externalStorageWriteable = false;
}
if (externalStorageWriteable) {
System.out.println("enough storage!");
// creation of a document-object
Document document = new Document();
try {
// we create a writer that listens to the document
// and directs a PDF-stream to a file
if (f.exists())
f.delete();
try {
f.createNewFile();
} catch (IOException e) {System.out.println(e);}
PdfWriter.getInstance(document, new FileOutputStream
(android.os.Environment.getExternalStorageDirectory()
.getAbsolutePath() + java.io.File.separator + "HelloWorld.pdf"));
// open + format the document
document.open();
document.add(new Paragraph("Hello World"));
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
document.close();
}
Intent printIntent = new Intent(this, PrintDialogActivity.class);
Uri hello = Uri.fromFile(f);
printIntent.setDataAndType(hello, "application/pdf");
printIntent.putExtra("title", "stuff");
startActivity(printIntent);
我得到這個錯誤,我有0想法做些什麼:
04-29 03:41:18.502: E/chromium(749): external/chromium/net/disk_cache
/backend_impl.cc:1107: [0429/034118:ERROR:backend_impl.cc(1107)]
Critical error found -8
我想知道我能嘗試玩這個工作。順便說一下,PrintDialogActivity來自Google網站的庫存。我關閉了應用程序設置中的Exchange,我已經允許將外部存儲寫入清單中,並且互聯網也已啓用。
感謝
檢查iText是否正常工作的最簡單方法是檢查外部存儲器上的PDF。如果它是腐敗的,讀者會告訴你。如果您在PDF中看不到「Hello World」,請提供例外。 – 2013-04-29 07:55:35
我用DDMS來檢查它,沒有顯示在「SD卡」文件夾中。有任何想法嗎? – user1993551 2013-04-29 14:37:31
你的logcat顯示任何錯誤,異常,消息,什麼? – 2013-04-29 14:52:25