我正在使用下面的代码来绘制文本并用 PDF 编写,但它不能在多个页面中绘制?解决这个问题的最佳方法是什么。
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageInfo = new
PdfDocument.PageInfo.Builder(pageWidth, pageheight, 3).create();
PdfDocument.Page page = document.startPage(pageInfo);
Canvas canvas = page.getCanvas();
TextPaint paint=new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.rgb(0, 0, 0));
paint.setTextSize((int) (7 * 2));
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
int textWidth = canvas.getWidth() - (int) (16 * 2);
StaticLayout textLayout = new StaticLayout(
edittextContent.getText().toString(), paint, pageWidth-50, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
int textHeight = textLayout.getHeight();
float x = ((pageWidth-15) - textWidth)/2;
float y = ((pageheight-15) - textHeight)/2;
// draw text to the Canvas center
canvas.save();
canvas.translate(15, 10);
textLayout.draw(canvas);
canvas.restore();
document.finishPage(page);
document.writeTo(fOut);
document.close();