0

I am relatively new to Java and Android. Having said that I am using the iText.jar file in my app to create a PDF from data entered by the user. I am starting with the basic example just to see how it works and play with it. For some reason, I either get errors, either it is read only or it does not exist. Hoping someone has run into a similar problem with a fix. My code is below that I am using. I have added the permissions in the android manifest. I didn't include every bit of code, just the relevant stuff. The GlobalVars is a class I use to store all the public variables.Also, the toast statement I am using to help debug and is where I am getting these error messages......

<public static final File location =     Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);>

<try {
        createPdf();
    } catch (FileNotFoundException | DocumentException e) {
        e.printStackTrace();
        errorString = e.getMessage();
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }>

<public void createPdf() throws FileNotFoundException, DocumentException {
    FileOutputStream pdfFile = new FileOutputStream(location.getAbsolutePath() + "/temp.pdf");
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, pdfFile);
    // step 3
    document.open();
    // step 4
    document.add(createDataTable());
    // step 5
    document.close();
}

public static PdfPTable createDataTable() {
    // a table with two columns
    PdfPTable table = new PdfPTable(4);
    // the cell object
    PdfPCell cell;
    // we add the cells with table.addCell()

    for (int x = 0; x < 40; x++) {
        cell = new PdfPCell(Phrase.getInstance(x + ": " + GlobalVars.inspectionResults[x]));
        table.addCell(cell);
    }
    return table;
}>

Here is the Logcat Errors:

10-29 01:08:56.730 2283-2340/com.abc.aeivehicleinspection E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb3fd33b0

10-29 01:09:02.722 2283-2340/com.abc.aeivehicleinspection E/Surface: getSlotFromBufferLocked: unknown buffer: 0xabac8a40

  • why didn't you post the stacktrace? – njzk2 Oct 29 '15 at 04:21
  • For some reason, I do not get anything when trying to run the debug. I apologize for my ignorance, but I am new to these programs and am still getting used to them. I have a lot of programming knowledge, but still trying to learn these..... – Victor Humphrey Oct 29 '15 at 04:24
  • If you get a toast, there is an exception (unless it is from another part of your program). You correctly log the stack trace of the exception, so it will appear in the logcat. get the logcat and post the stack trace. – njzk2 Oct 29 '15 at 04:26
  • I have not been able to get the logcat to come up and I don't know why. However, I am saving the error in the string and placing it in a textview at the end of the app to display the errors. Here is what it says: "/storage/17F3-3B1C/Download/temp.pdf: open failed: ENOENT (No such file or directory. – Victor Humphrey Oct 29 '15 at 04:48
  • I have tried just using a file name which is exactly what the example shows: – Victor Humphrey Oct 29 '15 at 04:49
  • Now I get the error "temp.pdf: open failed: OROFS (Read-only file system) – Victor Humphrey Oct 29 '15 at 04:55
  • Take a look at http://stackoverflow.com/questions/15711098/trying-to-create-a-file-in-android-open-failed-erofs-read-only-file-system – Mare Geldenhuys Oct 29 '15 at 06:34

0 Answers0