else if (id == R.id.print) {
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(2250, 1400, 1).create();
PdfDocument.Page page = document.startPage(pageInfo);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View content = inflater.inflate(R.layout.activity_main, null);
content.measure(1400, 2250);
content.layout(0,0, 2250, 1400);
content.draw(page.getCanvas());
document.finishPage(page);
String directory_path = Environment.getExternalStorageDirectory().getPath() + "/mypdf/";
File file = new File(directory_path);
if (!file.exists()) {
file.mkdirs();
}
String targetPdf = directory_path+"Табель.pdf";
File filePath = new File(targetPdf);
try {
document.writeTo(new FileOutputStream(filePath));
Toast.makeText(MainActivity.this, "Cохранено", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Log.e("main", "error "+e.toString());
Toast.makeText(MainActivity.this, "Ошибка: " + e.toString(), Toast.LENGTH_LONG).show();
}
document.close();