我使用以下代码使用
Android PDFDocument API(
https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html)从View编写PDF.
码
/**
* Writes given PDFDocument using content view.
*
* @param pdfDocument PDFDocument to be written.
*/
private void writePDFDocument(final PdfDocument pdfDocument) {
// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(PDF_PAGE_WIDTH, PDF_PAGE_HEIGHT, 1).create();
// start a page
PdfDocument.Page page = pdfDocument.startPage(pageInfo);
// draw view on the page
int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);
contentView.measure(measureWidth, measuredHeight);
contentView.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());
contentView.draw(page.getCanvas());
// finish the page
pdfDocument.finishPage(page);
}
问题
如果我正在写A4尺寸的PDF.
因此,如果我的视图大小超过我的PDF大小,如何自动将其写入第二页,那么如果视图大小超过pdf页面大小,那么这些视图会被切断.
提前致谢.