0

I have tried the code

@Override
protected void onActivityResult(int requestCode, int resultCode, 
                                @Nullable Intent data) 
{
    switch (requestCode)
    {
        case 10:
            if (resultCode==RESULT_OK) 
            {
                String path = data.getData().getPath();
                path_disp.setText(path);
                File file = new File(path);
                PdfDocument pdf = new PdfDocument(file.getAbsolutePath(), null);
            }
            break;
    }
}

but this gives me an error "PdfDocument() in PdfDocument cannot be applied to (java.lang.String , null)"

so low
  • 1
  • 7

1 Answers1

0

https://developer.android.com/reference/android/graphics/pdf/PdfDocument

Looks like the class PdfDocument doesn't have a constructor that can take a string.

// create a new document
PdfDocument document = new PdfDocument();

// crate a page description
PageInfo pageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create();

// start a page
Page page = document.startPage(pageInfo);

// draw something on the page
View content = getContentView();
content.draw(page.getCanvas());

// finish the page
document.finishPage(page);
. . .
// add more pages
. . .
// write the document content
document.writeTo(getOutputStream());

// close the document
document.close();

You have to create a Page first and then you can draw something on the canvas. In your case it would be

yourCanvas.drawText("Your string.")
billo
  • 134
  • 1
  • 6
  • "PageInfo pageInfo = new PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create();" Compiler not accepting as builder only executes with int and not with rect and int. what shall i change . – so low Nov 21 '19 at 11:01
  • PageInfo.Builder(int pageWidth, int pageHeight, int pageNumber) try it like this – billo Nov 21 '19 at 11:07
  • is it okay if i use findViewById(android.R.id.content); in "View content=getContentView();" instead of getContentView()? as getContentView() is not working. – so low Nov 21 '19 at 11:22
  • and how can i write the document's content to a predefined string – so low Nov 21 '19 at 11:26