iText landscape orientation and positioning?

前端 未结 4 1752
名媛妹妹
名媛妹妹 2021-02-05 01:22

I\'ve just started to work with iText (5.4.2, latest version) and there are two things that I haven\'t yet managed to get straight.

  • Creating documents in landscap
相关标签:
4条回答
  • 2021-02-05 02:08

    You're using PageSize.A4_LANDSCAPE, a variable that was introduced by a contributor and that should have never been added to the main release. Please use PageSize.A4.rotate() instead.

    It's not clear what you want to achieve with the lines:

    document.left(100f);
    document.top(150f);
    

    Those are getters, not setters. It looks as if you're assuming that PDF is similar to HTML. That assumption is wrong.

    If you want the image to be put 10 user units from the left and 15 user units from the top (in which case 100 and 150 are the wrong values), you could replace the 0 values in your Document constructor to define a left margin of 10 user units and the top margin 15 user units.

    Another way would be to define an absolute position for the image with the method setAbsolutePosition(). In that case, you need to be aware that the coordinate system is oriented in such a way that the lower-left corner of the page has the coordinate x=0 , y=0 for documents created from scratch.

    0 讨论(0)
  • 2021-02-05 02:12

    You can use this example this is work for me

     Document document = new Document();
     document.setPageSize(PageSize.A4.rotate());
    
    0 讨论(0)
  • 2021-02-05 02:14
    Document d = new Document(PageSize.A4.rotate(), 10f, 10f, 10f, 0f);
    

    this worked for me i just hacked off some bits from the one above

    0 讨论(0)
  • 2021-02-05 02:20
    iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4.Rotate(), 10f, 10f, 10f, 0f);
    
    0 讨论(0)
提交回复
热议问题