I tried to learn how to generate PDF for my Android application.
I followed the official documentation but the code didn't work.
the compiler found me some compilation error but all I did was to copy/paste the code from the code.
please take a look at the code and tell me why (:
PrintAttributes printAttributes = new PrintAttributes.Builder().
setMediaSize(PrintAttributes.MediaSize.ISO_A4)
.setColorMode(PrintAttributes.COLOR_MODE_COLOR)
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
.build();
PrintedPdfDocument document = new PrintedPdfDocument(this, printAttributes);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(new Rect(0, 0, 100, 100), 1).create();
// start a page
PdfDocument.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();