我搜索过它,但无法找到任何好的文档.
我正在使用 droidText 库生成 pdf
我有以下代码
public void createPDF()
{
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
File dir = new File(path);
if(!dir.exists()){
System.out.println("directory not exists");
dir.mkdirs();
}else{
System.out.println("directory exirsts");
}
System.out.println("path="+path);
Log.d("PDFCreator", "PDF Path: " + path);
File file = new File(dir, "sample.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1 = new Paragraph("Hi! I am generating my first PDF using DroidText");
Font paraFont= new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
//add …Run Code Online (Sandbox Code Playgroud) parse.com提供了一种使用object.saveEventually();在离线模式下保存对象的方法; call ..这将对象存储在本地dataStore中,除非与服务器进行同步.
问题是,我无法存储下面给定行的文件
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 80, stream);
byte[] byteArray = stream.toByteArray();
file = new ParseFile("pic.png",byteArray);
object.put("file.png", file);
object.saveEventually();
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误
java.lang.IllegalStateException: Unable to encode an unsaved ParseFile
Run Code Online (Sandbox Code Playgroud)
根据解析文档保存文件file.saveInBackground应该被调用...我认为saveInBackground仅在有互联网连接时才有效...
但我想要实现的是从本地dataStore获取数据(对象或文件),直到与服务器同步...
那么如何在离线模式下以这种方式保存文件,我可以从本地dataStore访问该文件,直到与服务器同步为止...