Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在android上写入pdf_Android_Pdf_Itext - Fatal编程技术网

无法在android上写入pdf

无法在android上写入pdf,android,pdf,itext,Android,Pdf,Itext,我正在使用以下代码创建一个pdf文件,但在执行该代码后,并没有在设备的物理位置上创建该文件 tempDir = Environment.getExternalStorageDirectory() + "/" + getResources().getString(R.string.external_dir) + "/"; ContextWrapper cw = new ContextWrapper(getApplicationContext()); File directory =

我正在使用以下代码创建一个pdf文件,但在执行该代码后,并没有在设备的物理位置上创建该文件

tempDir = Environment.getExternalStorageDirectory() + "/" + getResources().getString(R.string.external_dir) + "/";     
ContextWrapper cw = new ContextWrapper(getApplicationContext());   
File directory = cw.getDir(getResources().getString(R.string.external_dir), Context.MODE_PRIVATE); 
prepareDirectory();      
String uniqueId = getTodaysDate() + "_" + getCurrentTime() + "_" + Math.random();    

String current = uniqueId + ".pdf";       
File  mypath= new File(directory,current);    
System.out.println(".....................1");
try {
    mypath.createNewFile();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}
Document document = new Document();  
System.out.println(".....................2");
try {
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(mypath));
    System.out.println(".....................3");

    document.open();

    System.out.println(".....................4");
    Paragraph preface = new Paragraph();
    preface.add(new Paragraph("First Paragraph"));
    document.add(preface);
    System.out.println(".....................5");


    document.add(chap);
    document.close();
    System.out.println(".....................6");

} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    System.out.println(".................inside filenotfound exception");
    e.printStackTrace();
} catch (DocumentException e) {
    // TODO Auto-generated catch block
    System.out.println(".................inside document exception");
    e.printStackTrace();
}  

PdfPrinterGraphics2D
类是iText(对于Java)的一部分,但不是iTextG(对于Android/GAE)的一部分。如果出现“找不到”类异常,则说明您使用了错误的iText。您应该使用Android端口:

显示日志cat消息..11-26 15:03:12.642:E/dalvikvm(27435):找不到从方法com.itextpdf.text.pdf.PdfPrinterGraphics2D引用的类'com.itextpdf.text.pdf.PdfContentByte.createPrinterGraphics11-26 15:03:12.682:I/dalvikvm(27435):找不到从方法com.itextpdf.text.pdf.PdfContentByte.settextmatrix引用的方法java.awt.geom.AffineTransform.getMatrix您使用的是桌面版的iText还是Android端口?