HomeSketchwarePDF – Convert linear view to pdf document in Sketchware.

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:-


3 thoughts on “PDF – Convert linear view to pdf document in Sketchware.

  1. will not work anyway…i know about this…need one more code in on create event.

    1. It actually works like a charm. If you want the PDF to always be displayed after you click off the page, then and only then would you need a code for onCreate.

      Also when using this code, I had a syntax error ( from the quotation marks ) very easy fix.

Leave a Reply