1) Create a New project.
2) Add EditText as id= "edittext1", a Button as id ="button" with text"Save" and a Linear Layout as id ="linear1".
3) In that Linear Add an another EditText as id="edittext2".Set linear1 background colour WHITE.
4) Then Create a String variable as path.
5) On button1 click event add add source directly block with code:-
try{ android.graphics.pdf.PdfDocument document = new android.graphics.pdf.PdfDocument(); android.graphics.pdf.PdfDocument.PageInfo pageInfo = new android.graphics.pdf.PdfDocument.PageInfo.Builder(linear1.getWidth(), linear1.getHeight(), 1).create(); android.graphics.pdf.PdfDocument.Page page = document.startPage(pageInfo); Canvas canvas = page.getCanvas(); Paint paint = new Paint(); canvas.drawPaint(paint); linear1.draw(canvas); document.finishPage(page);
6) Then Set string path to as image below.
7) Add write string block to enable storage permission.
8) Then Add add source directly block with code:-
java.io.File myFile = new
java.io.File(path); java.io.FileOutputStream fOut = new java.io.FileOutputStream(myFile); java.io.OutputStreamWriter myOutWriter = new java.io.OutputStreamWriter(fOut); document.writeTo(fOut); document.close(); myOutWriter.close(); fOut.close(); Toast.makeText(getBaseContext(), "File Saved", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();}
9) Save and run project.
0 Comments