java Example
// 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();
See Also: PdfDocument Members
java Example
// 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();
This class enables generating a PDF document from native Android content. You create a new document and then for every page you want to add you start a page, write content to the page, and finish the page. After you are done with all pages, you write the document to an output stream and close the document. After a document is closed you should not use it anymore. Note that pages are created one by one, i.e. you can have only a single page to which you are writing at any given time. This class is not thread safe.
A typical use of the APIs looks like this: