I am working on an Android app need to generate a pdf report. But the report.pdf I get is 0 byte and can not be opened. I use iText 5.4.3 before and had the same problem. (Now I use droidText). droidText.0.5.jar was imported into a lib folder and added into Android Private Libraries (which is on the build path).
Here is my code to generate a simple hello world.
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public void onGeneratePDF(View v){
String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
dir = dir+"/Report/Report.pdf";
try {
Document document = new Document(PageSize.LETTER.rotate());
PdfWriter.getInstance(document, new FileOutputStream(dir));
document.open();
document.add(new Paragraph("test"));
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Manifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And the log
08-08 10:06:59.636: W/System.err(16633): Helvetica not found as resource.
(The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
08-08 10:06:59.641: W/System.err(16633): ExceptionConverter: java.io.IOException:
The document has no pages.
Anyone can help ? Thanks in advance :))