itextpdf的確定頁面上的具體坐標是通過坐標來確定的。
它們的坐標軸是這樣的:以左下角為原點的xy坐標軸。
在itextpdf的方法中中,定義某個點的位置,都是以左下方為原點坐標軸來確定。
如果要定義一個矩形框,如:Rectangle rect = new Rectangle(300, 300, 400, 400);
它的四個值,確定了矩形左下角和右上角的坐標。通過這種方式來確定矩形范圍。
itextpdf中一些坐標的含義:
1、頁面尺寸
System.out.println("頁面尺寸"); //當前頁面的對角坐標值,當前是A4紙 System.out.println("top:"+doc.getPageSize().getTop());//右上角y軸坐標 System.out.println("bottom:"+doc.getPageSize().getBottom());//左下角y軸坐標 System.out.println("left:"+doc.getPageSize().getLeft());//左下角x軸坐標 System.out.println("right:"+doc.getPageSize().getRight());//右上角x軸坐標 System.out.println();
打印結果:
頁面尺寸 top:842.0 bottom:0.0 left:0.0 right:595.0
2、正文尺寸
System.out.println("page正文尺寸"); //去除也邊距后對角值 System.out.println("top:"+doc.top());//右上角y軸坐標 System.out.println("bottom:"+doc.bottom());//左下角y軸坐標 System.out.println("left:"+doc.left());//左下角x軸坐標 System.out.println("right:"+doc.right());//右上角x軸坐標
打印結果:
page正文尺寸 top:806.0 bottom:36.0 left:36.0 right:559.0
3、頁邊距
System.out.println("margin尺寸"); //頁面邊距 System.out.println("top:"+doc.topMargin());//上邊距 System.out.println("bottom:"+doc.bottomMargin());//下邊距 System.out.println("left:"+doc.leftMargin());//左邊距 System.out.println("right:"+doc.rightMargin());//右邊距
打印結果:
margin尺寸 top:36.0 bottom:36.0 left:36.0 right:36.0