Announcement Announcement Module
Collapse
No announcement yet.
AbstractPdfView, change the rotation of documents Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


        • #5
          Re: AbstractPdfView, change rotation + add header and footer

          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,

          Comment


          • #6
            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.

            Comment

            Working...
            X