Android: PdfDocument generates empty pdf

前端 未结 4 1526
无人及你
无人及你 2020-12-14 19:20
        PdfDocument document = new PdfDocument();
        // crate a page description
        PageInfo pageInfo = new PageInfo.Builder(300, 300, 1).create();
                


        
4条回答
  •  Happy的楠姐
    2020-12-14 19:59

    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!

提交回复
热议问题