Results 1 to 6 of 6

Thread: AbstractPdfView, change the rotation of documents

  1. #1
    Join Date
    Aug 2004
    Posts
    7

    Default AbstractPdfView, change the rotation of documents

    I use the buildPdfDocument method in a subclass of AbstractPdfView to render a Pdf-document, but am not able to change the rotaton of the default A4 size of the document. I try to use
    Code:
    setPageSize(PageSize.A4.rotate())
    method in com.lowagie.text.Document, but still it stands up and will not lay down...

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    I've checked the code for the AbstractPdfView and by default, it sets the page size to A4. Resetting the page size (as you're doing) in your subclassed PdfView should work (according the iText code).

    Could you try to override the AbstractPdfView.getDocument() method and return a document using new Document(PageSize.A4.rotate()) and see what's happening then? If that doesn't work, it's an iText bug I think.

    Could you check back here after you've tried this and give us an update

  3. #3
    Join Date
    Aug 2004
    Posts
    7

    Default AbstractPdfView, change rotation + add header and footer

    Thanks for the reply. I tried to override the AbstractPdfView.getDocument() method and that worked well so this problem is now solved.

    But I got a new problem when I tried to add a header and a footer to the document. Then they would not appear on the front page of the document, only on the second and following pages.

    I found a solution to this by making a little change in the source code of the AbstractPdfView class. I added a new abstract method
    Code:
    protected abstract void setHeaderFooter(Document doc);
    to the class and make a call to it in the renderMergedOutputModel(...) metod after the PdfWriter object is instantiated. After what I understand from the iText documentation this object has to be instatiated before any change can be done to the header or footer. When I override this method in my subclass I can set the header and footer as I want and make them appear even on the front page.

    It would be nice to know if there is any other solution to this.

  4. #4
    Join Date
    Aug 2004
    Posts
    7

    Default AbstractPdfView, change rotation + add header and footer

    Thanks for the reply. I tried to override the AbstractPdfView.getDocument() method and that worked well so this problem is now solved.

    But I got a new problem when I tried to add a header and a footer to the document. Then they would not appear on the front page of the document, only on the second and following pages.

    I found a solution to this by making a little change in the source code of the AbstractPdfView class. I added a new abstract method
    Code:
    protected abstract void setHeaderFooter(Document doc);
    to the class and make a call to it in the renderMergedOutputModel(...) metod after the PdfWriter object is instantiated. After what I understand from the iText documentation this object has to be instatiated before any change can be done to the header or footer. When I override this method in my subclass I can set the header and footer as I want and make them appear even on the front page.

    It would be nice to know if there is any other solution to this.

  5. #5
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default Re: AbstractPdfView, change rotation + add header and footer

    Quote Originally Posted by domkat
    It would be nice to know if there is any other solution to this.
    You should be able to do this overriding the AbstractPdfView.buildPdfMetadata() method I think. The javadoc and method name could possibly be improved, but you get the Document object as a parameter before the document.open() method is called so the following (untested, taken from the iText docs) should work:
    Code:
    protected void buildPdfMetadata(Map model, Document document, HttpServletRequest request) {
      HeaderFooter header = new HeaderFooter(new Phrase("This is a header."), false);
      HeaderFooter footer = new HeaderFooter(new Phrase("This is page "), new Phrase("."));
      document.setHeader(header);
      document.setFooter(footer);
    }
    Regards,
    Darren Davison.
    Public Key: 0xE855B3EA

  6. #6
    Join Date
    Aug 2004
    Posts
    7

    Default

    Thanks for a quick answer. When I first wrote my class I was still using the 1.0 version of the framework, and the AbstractPdfView.buildPdfMetadata(...) method was not yet added, so I could not make use of it then. Now I have installed the last version of the framework, and I have tested this new method and it works well so I will use this from now on.

Similar Threads

  1. Replies: 0
    Last Post: Aug 18th, 2005, 08:33 AM
  2. Change Password interim step
    By markstgodard in forum Security
    Replies: 5
    Last Post: Jul 19th, 2005, 02:59 AM
  3. Replies: 1
    Last Post: May 29th, 2005, 06:03 AM
  4. Working with documents in a rich client
    By adepue in forum Swing
    Replies: 0
    Last Post: Feb 16th, 2005, 06:23 PM
  5. problems in Change the contact-cas url
    By richardsang2004 in forum Security
    Replies: 3
    Last Post: Nov 10th, 2004, 07:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •