PDA

View Full Version : AbstractPdfView, change the rotation of documents



domkat
Sep 22nd, 2004, 08:35 AM
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
setPageSize(PageSize.A4.rotate()) method in com.lowagie.text.Document, but still it stands up and will not lay down...

Alef Arendsen
Sep 28th, 2004, 02:20 PM
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

domkat
Oct 14th, 2004, 01:42 AM
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
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.

domkat
Oct 14th, 2004, 01:46 AM
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
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.

davison
Oct 14th, 2004, 03:01 AM
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:

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,

domkat
Oct 15th, 2004, 06:59 AM
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.