我有字节流并使用字节流创建pdf。我试试这段代码。
byte[] bytes;
File createfile = new File("/sdcard/Androidrox/");
createfile.mkdirs();
File outputFile = new File(createfile, "Sample.pdf");
FileOutputStream fos = new FileOutputStream(outputFile);
PdfWriter.getInstance(doc, fos);
doc.open();
String strByte = editText.getText().toString();
bytes=strByte.toString().getBytes(Charset.forName("UTF-8"));
String filepath = "/sdcard/Androidrox/Sample.pdf";
OutputStream pdffos = new FileOutputStream(filepath);
pdffos.write(bytes);
pdffos.flush();
pdffos.close();
我无法打开文件。 "错误,打开文档时出错。请帮我识别错误
答案 0 :(得分:0)
尝试此操作来创建PDF文件
File FILE;
PdfWriter pdfWriter;
FILE = createDirectory(path, projectListBean.getProjectName() + ".pdf");
Document document = new Document();
pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(FILE));
public File createDirectory(String path, String filename) throws FileNotFoundException {
File directory = new File(path);
directory.mkdirs();
return new File(directory, filename);
}