1

I have managed to create my own pdf documents with the help of PdfDocument Class. But what if I already have a pdf in my (let's say) assets folder and I want to e.g. draw something on it. Is it possible?

I have my

PdfDocument document;

But how can i read the powerpoint i have inside my project?

I am guessing i have to use a File but i cannot work this out.

I tried something like this, although I know it is wrong

PdfDocument document = new PdfDocument(getAssets().open("powerpoint"));
Matusalem Marques
  • 2,399
  • 2
  • 18
  • 28
monkeydkon
  • 95
  • 9
  • About what filetype are you talking here? *.ppt or pptx? Or did you talk about a converted powerpoint file which is now a pdf file? – Lonzak Mar 09 '20 at 10:13

2 Answers2

2

From what I understand you ask two questions:

  1. But what if I already have a pdf in my (let's say) assets folder and I want to e.g. draw something on it. Is it possible?

With the android PdfDocument class, you can create a PDF out of Web content (via WebView), a Canvas (using views or the native Canvas drawing API), or an image. You have to use third-party PDF libraries (like iText or the PDFBox Android port) to change existing PDFs.

  1. But how can i read the powerpoint i have inside my project?

For displaying powerpoint there is a separate project called 'pptviewer-android'. However it is not maintained anymore, so if you have problems you probably have to figure those out by yourself. An examplary use can be found here.

PPTViewer pptViewer = (PPTViewer) findViewById(R.id.pptviewer);
pptViewer.setNext_img(R.drawable.next)
        .setPrev_img(R.drawable.prev)
        .setSettings_img(R.drawable.settings)
        .setZoomin_img(R.drawable.zoomin)
        .setZoomout_img(R.drawable.zoomout);
pptViewer.loadPPT(this,"/home/powerpoint.pptx");
Lonzak
  • 9,334
  • 5
  • 57
  • 88
0

Not sure whether I have correctly understood your problem statement: Please try this out:

if (Desktop.isDesktopSupported()) {
try {
    File fileToOpen = new File("/assets/file.pdf");
    Desktop.getDesktop().open(fileToOpen);
} catch (IOException ex) {
    // log Error
}
}
Devkinandan Chauhan
  • 1,785
  • 1
  • 17
  • 42