我们可以在android中创建PDF文件吗?
- 我已经尝试了所有谷歌搜索。
- 还看到了更多的例子。
我试过这个,
File f=new File("/data/data/com.pdf/test1.pdf"); Log.d("test", "created"); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(f)); document.open(); document.addTitle("My first PDF"); document.addSubject("Using iText"); document.addKeywords("Java, PDF, iText"); document.addAuthor("Lars Vogel"); document.addCreator("Lars Vogel"); Paragraph paragraph = new Paragraph("This is left aligned text with indentation"); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.setIndentationLeft(50); document.add(paragraph); document.close(); Toast.makeText(this, "Pdf Created", Toast.LENGTH_LONG).show();
但这给出了错误,
08-11 16:53:38.446: E/AndroidRuntime(2484): FATAL EXCEPTION: main
08-11 16:53:38.446: E/AndroidRuntime(2484): java.lang.NoClassDefFoundError: com.itextpdf.text.Document
08-11 16:53:38.446: E/AndroidRuntime(2484): at com.pdf.PDFReaderActivity.onCreate(PDFReaderActivity.java:28)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.Activity.performCreate(Activity.java:4465)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.os.Looper.loop(Looper.java:137)
08-11 16:53:38.446: E/AndroidRuntime(2484): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-11 16:53:38.446: E/AndroidRuntime(2484): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 16:53:38.446: E/AndroidRuntime(2484): at java.lang.reflect.Method.invoke(Method.java:511)
08-11 16:53:38.446: E/AndroidRuntime(2484): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-11 16:53:38.446: E/AndroidRuntime(2484): at com .android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-11 16:53:38.446: E/AndroidRuntime(2484): at dalvik.system.NativeStart.main(Native Method)