Android: PdfDocument generates empty pdf

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


        
4条回答
  •  执笔经年
    2020-12-14 20:22

    I had the exact same problem but in order to implement @user2021505 solution (that works) I should have done a major refactor, so I solved the issue this way

    // ...
    PdfDocument.Page page = document.startPage(pageInfo);
    
    TextView textView = new TextView(ctx);
    textView.setText("1,2,3");
    
    // here the solution
    int left = 0;
    int top = 0;
    int width = 200;
    int height = 200;
    textView.layout(0,0,width,height);
    
    canvas.save()
    canvas.translate(left,top);
    
    textView.draw(page.getCanvas());
    
    canvas.restore()
    

提交回复
热议问题