我正在尝试生成一个简单的 PDF 并将其传递给 Google Cloud Print,但是当我尝试将 PDF 打印到我的谷歌驱动器时没有任何反应。(登录有效)对于初学者,我什至如何验证我的 PDF 是完整且有效的?我觉得我正在接受 iText 的话。
另外,我收到一些错误告诉我
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);
我收到这个错误,我不知道该怎么办:
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,我已经允许在清单中写入外部存储,并且 Internet 也已启用。
谢谢