PdfDocument document = new PdfDocument();
// crate a page description
PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
If somebody is creating layout on the fly, and doesn't have its view attached to activity or fragment which gets rendered and measured at some point in activity or fragment lifecycle, there is another approach:
rootView.measure(800, 480);
rootView.layout(0, 0, 800, 480);
This way your rootView width and height will not stay 0 and there will be something that will be rendered to document. Courtesy of the answer here!