Use PdfDocument generate PDF files, when the content changes, it will have an empty file, whether it is page.getCanvas () drawText ( "12345", 20, 50, paint).;
still is
view1.draw(canvas);
Code is as follows:
public void actionGenPdf (View View)
{
// create a PDF text object
PDFDocument Document PDFDocument new new = ();
// create this page of information, the parameter indicates Builder width and height of the page, and which page
PdfDocument. = new new PdfDocument.PageInfo.Builder PageInfo PageInfo (595, 843,1) .create ();
// this page generating
PdfDocument.Page page document.startPage = (PageInfo);
// draw on this page, i.e. to the needed to view the page view of the canvas painting
the Paint Paint new new = the Paint ();
paint.setColor (as Color.BLACK.);
paint.setTextSize (20 is);
the canvas page.getCanvas = canvas ();
/ * for (int I 0 =; I <10; I ++) {
String STMP = "12345";
. page.getCanvas () drawText ( "12345", 20 is, 50, Paint);
canvas.translate(0, 30);
}*/
TextView view1 = new TextView(this);//getContentView();
view1.layout(0, 0, 200, 200);
view1.setText("Hello");
TextView view2 = new TextView(this);//getContentView();
view2.layout(0, 0, 200, 200);
String sTmp = "Good"+Integer.toString(10);
final String ss = sTmp;
view2.setText(ss);
view1.draw(canvas);
canvas.translate(0, 200);
view2.draw(canvas);
canvas.save();
/*for(int i = 0; i < 10; i++) {
TextView view1 = new TextView(this);//getContentView();
view1.layout(0, 0, 200, 200);
view1.setText("Hello"+Integer.toString(i));
Toast.makeText(this,"Hello"+Integer.toString(i), Toast.LENGTH_SHORT).show();
view1.draw(canvas);
// Move the canvas for the next view.
canvas.save();
canvas.translate(0, 50);
}*/
document.finishPage(page);
// 输出到文件
try {
String filePath = "/sdcard/";
//String filePath = Environment.getExternalStoragePublicDirectory("").getAbsolutePath();
//String filePath = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "easy.pdf";
File file = new File(filePath, fileName);
FileOutputStream outputStream = new FileOutputStream(file);
document.writeTo(outputStream);
PubUtils.notifySystemToScan(this, filePath + fileName);
Toast.makeText(this, "导出完成", Toast.LENGTH_SHORT).show();
SoundUtils.getInstance().playSuccess();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}