PDF - Convert linear view to pdf document in Sketchware.


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 the string path to as shown 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 the project.
Ads:-

You can watch the below video:-

Comments

Post a Comment

Popular posts from this blog

How to make a website in 2019 with no investment.

Make a layout with rounded corners in sketchware

Add menu in actionbar in Sketchware